Phone Number Validation

This section is for posting questions which are not directly related to WYSIWYG Web Builder.
Examples of off topics: web server configuration, hosting, programming related questions, third party scripts.

Note that these questions will generally not be answered by the administrators of this forum.
Post Reply
davidflash
 
 
Posts: 28
Joined: Fri Jul 17, 2015 8:25 pm

Phone Number Validation

Post by davidflash » Fri Jan 19, 2018 6:54 am

Ok, I have been trying to guess where to place this javascript script.
I have a editbox with a id = Phone. I have this javascript code that I trying to test. My problem is I am not sure where to place the javascript script . Do I place it in the form. I think not, So I placed it in the Page Html, at the end of page.

Here's the script.

function formatPhone(num) {
var str = num.toString();
alert(str);
var matched = str.match(/\d+\.?\d*/g);

// 10 digit
if (matched.length === 3) {
return '(' + matched[0] + ') ' + matched[1] + '-' + matched[2];
// 7 digit
} else if (matched.length === 2) {
return matched[0] + '-' + matched[1];
}
// no formatting attempted only found integers (i.e. 1234567890)
else if (matched.length === 1) {
// 10 digit
if (matched[0].length === 10) {
return '(' + matched[0].substr(0, 3) + ') ' + matched[0].substr(3, 3) + '-' + matched[0].substr(6);
}
// 7 digit
if (matched[0].length === 7) {
return matched[0].substr(0, 3) + '-' + matched[0].substr(3);
}
}

// Format failed, return number back
return num;
}

And here's the problem I tried placing an alert(str) just to see if the value is being sent to the function properly on a changed event, but when the alert is displayed, I get:
[object HTMLInputElement] ??

and not the value of num which I am passing to it from the onchange event of the editbox Phone, I select javascript function from the action dropdown and put in the javascript line formatPhone(Phone)

Any clue as to why the value of Phone is not being passed to the function, formatPhone ????

Any assistance will be appreciated..

The user guide does not clearly tell me the difference in the condition using the change feature vs the event using the onchange event??

Can anyone clarify the differences?

Thanks

User avatar
Pablo
 
Posts: 13100
Joined: Tue Mar 28, 2006 12:00 pm
Location: Europe
Contact:

Re: Phone Number Validation

Post by Pablo » Fri Jan 19, 2018 7:15 am

Please note that I cannot assist you with custom code.

The code should be inside the Page HTML, between <script> tags.

Conditions are an advanced version of events.
Events is standard HTML functionality, conditions are specific to WWB.
http://wysiwygwebbuilder.com/conditions.html

For validation you should use events.

User avatar
BaconFries
 
 
Posts: 4017
Joined: Thu Aug 16, 2007 7:32 pm

Re: Phone Number Validation

Post by BaconFries » Fri Jan 19, 2018 7:28 am

The script is invalid due to opening and closing tags <script> </script> missing! just as Pablo you can place it using the Page HTML. It can also be done easier using regex see the following for Telephone Number Validation
Telephone Number Validation
Similar Question
Similar

davidflash
 
 
Posts: 28
Joined: Fri Jul 17, 2015 8:25 pm

Re: Phone Number Validation

Post by davidflash » Fri Jan 19, 2018 2:36 pm

I have read many times in the forum, that one can not expect assist with custom programming, and I do appreciate the clarification between the change vs onchange, however

I do have the opening and closing strip tags, I just thought I needed them to show you the actual code. My point is why do you think the value of the editbox, Phone is not being passed to the formatPhone function. As I stated I put an alert message just to make sure WWB is at least recognizing the script (originally, I wasn't too sure as I stated before, where to place the javascript.

So what I have is a simple function, formatPhone() being pass the value of the editbox (Phone) like this
formatPhone(num). The very first two lines in the function I used an alert statement to tell me if the value in being passed like this
var x=num;
alert (num);

This is what I get in the alert message:
[object HTMLInputElement] ???


So is it possible, in WWB userguide to give a simple example of how to properly pass the value of an editbox to a function???

Do I need to but some sort of html element tag around the editbox value when passing so the function to recognize the editbox value ???

Any assistance will be appreciated... !!!!!

User avatar
Pablo
 
Posts: 13100
Joined: Tue Mar 28, 2006 12:00 pm
Location: Europe
Contact:

Re: Phone Number Validation

Post by Pablo » Fri Jan 19, 2018 3:04 pm

Without seeing the complete page it will be difficult to give you any meaningful advise about this.
Please share the URL of the page so I can see what you have done.

The reason why I cannot assist you with programming related issues is that I do not know your level of expertise.
If you do not have any HTML/JavaScript knowledge, then it may take me days to explain what you need to do.
This issue is not directly related to WWB. This is standard HTML/JavaScript functionality and function calls work the same as in any other editor.

User avatar
BaconFries
 
 
Posts: 4017
Joined: Thu Aug 16, 2007 7:32 pm

Re: Phone Number Validation

Post by BaconFries » Fri Jan 19, 2018 9:18 pm

Did you write this yourself? or was it sourced externally? if so provide a link to its source. Where to insert? once the opening and closing tags are added you would place the full script in Page HTML between <head></head>. If this doesn't work then it may be a issue with the script being invalid. It could also be that the script needs to be placed at the end of the code between the <body></body> (which I doubt). Have you possibly enabled minify or enabled save as external?. It could be a combination of issues this is why it is mentioned that no help is offered as it takes time to view/debug what may be wrong. As mentioned if the script is from a external source provide a link to it so it can be checked that nothing is missing.

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests