CS3, PHP, Javascript: Auto-formatting phone number pre-post

Hi guys and gals, I'm creating a simple user registration form, with a text field to have the user enter their phone number (this should autocorrect as the user types it). Grabbed a javascript snippet online, and I see whats going on in the code, but for some reason, its no workey
Have 3 parts to the webpage, these are:
The Javascript: "includes/ValidatePhone.js"
// JavaScript Document
<SCRIPT LANGUAGE="JavaScript">
var n;
var p;
var p1;
function ValidatePhone(){
p=p1.value
if(p.length==3){
     //d10=p.indexOf('(')
     pp=p;
     d4=p.indexOf('(')
     d5=p.indexOf(')')
     if(d4==-1){
          pp="("+pp;
     if(d5==-1){
          pp=pp+")";
     //pp="("+pp+")";
     document.form1.number.value="";
     document.form1.number.value=pp;
if(p.length>3){
     d1=p.indexOf('(')
     d2=p.indexOf(')')
     if (d2==-1){
          l30=p.length;
          p30=p.substring(0,4);
          //alert(p30);
          p30=p30+")"
          p31=p.substring(4,l30);
          pp=p30+p31;
          //alert(p31);
          document.form1.number.value="";
          document.form1.number.value=pp;
if(p.length>5){
     p11=p.substring(d1+1,d2);
     if(p11.length>3){
     p12=p11;
     l12=p12.length;
     l15=p.length
     //l12=l12-3
     p13=p11.substring(0,3);
     p14=p11.substring(3,l12);
     p15=p.substring(d2+1,l15);
     document.form1.number.value="";
     pp="("+p13+")"+p14+p15;
     document.form1.number.value=pp;
     //obj1.value="";
     //obj1.value=pp;
     l16=p.length;
     p16=p.substring(d2+1,l16);
     l17=p16.length;
     if(l17>3&&p16.indexOf('-')==-1){
          p17=p.substring(d2+1,d2+4);
          p18=p.substring(d2+4,l16);
          p19=p.substring(0,d2+1);
          //alert(p19);
     pp=p19+p17+"-"+p18;
     document.form1.number.value="";
     document.form1.number.value=pp;
     //obj1.value="";
     //obj1.value=pp;
setTimeout(ValidatePhone,100)
function getIt(m){
n=m.name;
//p1=document.forms[0].elements[n]
p1=m
ValidatePhone()
function testphone(obj1){
p=obj1.value
//alert(p)
p=p.replace("(","")
p=p.replace(")","")
p=p.replace("-","")
p=p.replace("-","")
//alert(isNaN(p))
if (isNaN(p)==true){
alert("Check phone");
return false;
</script>
And then we have the actual PHP Form, "includes/Users_Insert.php":
<form method="post" id="form1" action="<?php echo KT_escapeAttribute(KT_getFullUri()); ?>" enctype="multipart/form-data">
<table>
     <th class="WADADataTableHeader">Phone Number:</th>
     <td>
          <input type="text" name="number" id="number" size="32" onclick="javascript:getIt(this)" />
          <?php echo $tNGs->displayFieldHint("number");?>
          <?php echo $tNGs->displayFieldError("Users", "number"); ?>
        </td>
     </tr>
      <tr>
          <td class="WADADataNavButtonCell" nowrap="nowrap">
          <input type="image" name="KT_Insert1" id="KT_Insert1" value="Insert record" src="../WA_DataAssist/images/Pacifica/Refined_insert.gif" />
       </td>
          <td class="WADADataNavButtonCell" nowrap="nowrap"><a href="users.php" title="Cancel">
               <img border="0" name="Cancel" id="Cancel" alt="Cancel" src="../WA_DataAssist/images/Pacifica/Refined_cancel.gif" /></a></td>
     </tr>     
</table>
And here is the calls to put all of that together, "add_user.php":
<html><head><title></title>
<script src="includes/ValidatePhone.js" type="text/javascript"></script>
</head>
<body>
<?php include("includes/Users_Insert.php"); ?>
</body>
</html>
(didn't paste the whole website obviously, just the parts that should be relevant).
Anyone see anything in the code as to why this wouldn't be working as intended?

You are not telling your form to validate the phone no.
For a brief description of validating a form see - http://www.w3schools.com/jS/js_form_validation.asp
Take special notice of - onsubmit="return validate_form(this)"
PZ

Similar Messages

  • Formatting phone number: how to get rid of (...)?

    I live in Romania, and Contacts incorrectly formats phone numbers of the type xxxx xxx xxx (10 digit, the national standard, out of which the first is zero) into (xxxx) xxx xxx, i.e. inserting brackets before the first and after the 4th digit respectively. This is wrong. The bug is seemingly banal, yet it has bad consequences: if phone numbers are exported to Android, some Android devices, not all, alas, cannot dial such numbers and the process is stopped. Well, this may be a bug in Android, nevertheless the problem exists.
    A workaround is to choose another country as standard, e.g. Czech Republic. It works, but only for numbers added from that/this moment on, it does not remove (...) from the existing numbers.
    Q: how can I remove those stupid brackets (....) from the existing phone numbers? I need a global solution, a script or something...
    I reported the issue to Cupertino but they seem to be extremely slow, I do not understand why. Those brackets are incorrectly inserted, the national standards specifies a 10-digit number, out of which the first is zero, which is removed in case of international calls, and the prefix is added.

    Self answer: I changed country at hazard to Czech Republic, and all the phone numbers have been meanwhile changed from the wrong format (xxxx) xxx xxx to the correct format 0 xxx xxx xxx
    Praise be to hazard settings.
    P.S. Yes, I marked myself with a green bingo.

  • Custom field to format phone number?

    Is it possible to create a custom field for a list item to format a phone number (e.g. take 555-555-5555 and format it to (555) 555-5555)?  Does anyone have any examples?

    Hi,
    If you want to format the phone number to (555)555-5555, you can create a calculated column base on the phone number column and set its formula as” ="("&REPLACE([phone number],4,1,")")” .
    For more information about formula, please refer to: http://office.microsoft.com/en-us/sharepointtechnology/CH100650061033.aspx
    Hope it can help you.
    Xue-Mei Chang

  • Formatting Phone Number

    Man I'm trying to format a 10 digit phone number to display as (xxx)xxx-xxxx... how do i do it? I'm very green w/ sql... Any help please!?

    use a SUBSTR() here is an example.
    SQL> select '('||substr('8001434444',1,3)||')'||
      2         substr('8001434444',4,3)||'-'||substr('8001434444',7,4) phone
      3    from dual;
    PHONE
    (800)143-4444
    SQL>

  • Generic funtction  return  format string Phone Number

    Hi
    I tried , tried but nothing
    I need build a Generic Function formating phone number, passing Type Telephone (Res,Cml,Cel...etc wiht 3 letters ) , Prefix can to have 3 or 4 digits and Sufix wih 4 digits
    How Can I to do It ?
    where can I to find tutorial about Regular Expression
    thank

    Asking the same question again?
    Re: Function that to Format
    Look in the documentation for regular expressions (it's not difficult to search you know!)
    http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14251/adfns_regexp.htm#ADFNS1003

  • How to change phone number for messages on ipad

    How do I change the auto-selected phone number on my iPad for Message

    My experties is not really in ipads but im pretty sure that if you go into settings and scroll down until you find imassage tap on it and then tap on send and recive and click add another email/phone number hope that works for you

  • AS3 Auto Format not recognizing comments

    Something is corrupt with my Flash Professional CS5 Actionscript Auto format:
    Comments within a block, such as ' // ' or block comments ' /* ... */ ' are tripping up the Auto Formattor, which returns this error: ' Error with autoformat near line: }  '.
    Comments before package block don't cause an error.
    When I remove comments within package block, Auto format works correctly.
    How can I fix my Flash CS3 ActionScript editor Auto format?

    the problem you're seeing is the least of the known problems with auto-formatter.  the worst is the auto-formatter change change well-written code to be mal-formed code.
    so, while i don't think you can fix your auto formatter, what you can do is copy chunks of code to a new fla or as file and auto-format that chunk.
    then check that it's been formatted correctly and nothing essential has been changed.  (ie, at least, check for errors.)  if everything looks ok, replace the unformatted chunk in your original file with the formatted chunk.
    that's the wisest way to use auto-formatter.   it's also good to know and use the undo so you can always undo an auto-format botch.

  • I can't log in my phone number is

    Can't log in to find my billing update

    Hey 
    Welcome to the EE Community!
    What error message do you see when you try and log in? I take it you've registered for the online service? 
    I'd try and clear your cookies & cache, and perhaps try using another browser to log in, but if you can get back to me with answers to the above, I'll see if I can help you further. 
    Cheers,
    Titanium
    Was my post helpful? Please take 2 seconds to hit the 'Kudos' button below
    P.S - It's probably best to avoid including your full phone number in posts etc in the interests of personal privacy

  • I can't log in my phone number is 07508335959

    Can't log in to find my billing update

    Hey 
    Welcome to the EE Community! What error message do you see when you try and log in? I take it you've registered for the online service?  I'd try and clear your cookies & cache, and perhaps try using another browser to log in, but if you can get back to me with answers to the above, I'll see if I can help you further.  Cheers,
    Titanium
    Was my post helpful? Please take 2 seconds to hit the 'Kudos' button below  P.S - It's probably best to avoid including your full phone number in posts etc in the interests of personal privacy

  • How can i remove the mobile number i posted t iden...

    How can i remove the mobile phone number i posted to identify SMS messages in Skype -> Preference -> messaging ?

    zahertub wrote:
    How can i remove the mobile phone number i posted to identify SMS messages in Skype -> Preference -> messaging ?
    Hello,
    Only a Moderator can do that. If you provide me with the link to your post I will remove it for you.
    TIME ZONE - US EASTERN. LOCATION - PHILADELPHIA, PA, USA.
    I recommend that you always run the latest Skype version: Windows & Mac
    If my advice helped to fix your issue please mark it as a solution to help others.
    Please note that I generally don't respond to unsolicited Private Messages. Thank you.

  • Phone number format

    Just switched from pearl to 8330. When I loaded contacts from outlook, it formatted the phone numbers in 8330 as 0000000000. Format for my outlook and pearl is (000) 000-0000. Is there a way to get the number to format the same as my outlook as my pearl did?

    No worries
    That's what Discussions are here for...
    The strangest thing for me was that my 'auto format' option was - unbeknownst to me - switched on all this time. But it was NOT formatting anything. Go figure!

  • Phone number display format

    We are looking for a way to personalize the display format of phone number.
    I am at a company where there is a SAPphone or alike software connection to auto-dail using the SAP screen. Other then most companies here this is done from ECC rather then from CRM.
    For this, the Phone numbers are stored flat, without spaces, hashes and the like.
    In SAP there are setting for how to display date and numbers. I did not yet find a way to do the same with phonenumbers. There is an international requirement on how to display the numbers, and storing these numbers formatted is in my opinion not the preferred way to do it.
    There are function modules to format the numbers from flat stored numbers, but that will mean cloning standard transactions to Z versions so that the FM can be used. I would rather not do this too.
    Anyone any ideas?

    I am having the same issue with My Treo 700.  Did anyone find a resolution to this problem.  I think it is more than annoying.  For no reason the formatting just changed. 
    Thanks for you help.

  • Phone number format in Mountain Lion

    My old Address Book (prior to Mountain Lion's change to Contacts) had hundreds of phone numbers wirth the preference that they would NOT be auto formatted --- I entered the numbers just as I wanted them to appear. Now, after updating to Mountain Lion, all my phone numbers ar formatted the SAME (U.S. convention with use of parenthesis) which is not what I want. Anyone know of a workaround (or will Apple correct this with an update?).

    D. Hoffmann wrote:
    Apple's software engineers probably all live in the greater San Francisco are, where there aren't any area code overlays, which would potentially explain why they didn't think to allow xxx-xxx-xxxx as an alternative format.
    I think the explanation is that they all have cell phones. Apple expects everyone to be in the habit of prefixing all phone numbers with "+<country code>". If you do that, your cell phone will be smart enough to figure out how many digits it needs to dial. Land lines can't do that. Here in Ontario, things are pretty antiquated, If I dial a 905 number, it may or may not be local. I can't tell until I try. If I don't add the 1, I'll be chastised for attempting to make a long distance call without the 1 and get hung up on. If I just add the one and don't need it, I'll be chastised for that too and hung up on.
    So, if you create a phone number in Contacts with "+1", you get a US-style number useable anywhere in the world from a cell phone. If you prefix with a "+33", you get a French-style number useable from anywhere on a cell phone. Apple doesn't do hybrids because that assumes you are dialing the number by hand and no one does that anymore.

  • Need to have Phone Number field as just numbers with no formatting.

    We have a web service that is passed the work phone field from the contact object. That WS uses the phone number to auto-dial the customer's number for our sales reps.
    My issue is that the WS expects to just see the area code and the phone number as digits as 1235554444. It has been working fine for over a year and recently been failing as now the numbers come in with a "+" sign.
    The format seems to change depending on the time of day I look at the fields and is random for each user. The company profile is set to USA as the default and so are the user's locale settings.
    How do I make the "+" go away?
    I have tried various settings and couldn't seem to find one that didn't give me the formatting. I've also tried to copy the work phone field to a hidden field and using WF to strip out the "+" but there seems to be no way to do a REPLACE() function in a WF rule.
    Any ideas?

    So after spending enough time with this I was able to find a way around the issue. Ultimately I needed a phone number format that was fixed and would not mask the data per the user's locale settings. It also needed to be just area code and phone number shown as 1112223333.
    On the contact object, a new field was created as a Short Text. Then a WorkFlow as created that copies over the value from the WorkPhone field into this unformatted number so that it can be passed to our Web Service.
    It took a while for me to figure this out since if you just use the WorkPhone variable you get all the masking based on locale. I didn't have the functions available to me in the WorkFlow to just strip spaces and "+" or "( )" so I needed it to be as close as I coudl to just a basic phone number. By using the FieldValue() function it seemed to take a number like 1 (555) 444-4444 and return 1 555 4444444. This works no matter if it was +1 555 4444444 or +41 555 4444444 so I could then use some pattern logic.
    This is what I used to copy that data over to my temp/work field which is now passed to our click-to-dial function.
    Mid(FieldValue('<WorkPhone>'), InStr(FieldValue('<WorkPhone>'),' ') + 1,3) + Right(FieldValue('<WorkPhone>'),7)

  • Allow Multiple Phone Number Formats

    Hi folks,
    In the past I have always set the Phone Number format using the simple Arbitrary Mask feature in the text box properties e.g. (99) 9999 9999 but I have a form where two different phone number formats are acceptable (an Australian landline OR mobile).
    They are:
    (99) 9999 9999
    9999 999 9999
    Is this only possible through the magic of Javascript? I have tried Googling and found nothing.

    Thank you for your reply GKaiseril. I think I'm starting to undertsand it a little bit, especialyul after reading a similar thread that you contruibuted to here: http://forums.adobe.com/thread/861867
    My understanding is that the "vr re_NA_Phone_Commit =" bit specifies where the spaces are in the strong of numebrs, where the brackets go etc. But doesn't this still only set one type of format?
    If I use the following code, it turns 0399999999 (an example landline number) into (03) 5499 9999, great! But if I typed in 0499999999 (an example mobile number) I want it to become 0499 999 999 becasue that's how we format mobile numbers.
    // custom format
    var re_NA_Phone_Commit = /^\(?([0-9]{2})\)?[. ]?([0-9]{4})[-. ]?([0-9]{4})$/
    if(re_NA_Phone_Commit.test(event.value)) 
    event.value = "("+ RegExp.$1 +") " + RegExp.$2 + "-" + RegExp.$3;
    else {
    event.value = "";
    event.rc = false;
    // end custom format

Maybe you are looking for

  • After upgrade to 10.8.3 cannot get email

    This is very frustrating.  After upgrading to 10.8.3  i cannot get my emails.  I have seen people with the same issue however no one has answered them.  I have googled, binged, yelled, cried, laughed and I got nothing!  If anyone have finally got a f

  • New voice-over recording workflow?

    I just dug up what's new in the update I just installed, and I'm not seeing the expected "Voice-over Record button" after following the described steps. Am I missing something? Premiere Pro says it's up to date, and I was able to expore the other new

  • Updgrade from 11.2.0.1 to 11.2.0.3 on 2 node Rac -ASM ON windows 2008 r2

    Hi Guys, We are going to upgrade our 24x7 system (2 node RAC ASM On windows 2008 R2) from 11.2.0.1 to 11.2.0.3. I appreciate if any one let me know the oracle my support document no. or step by step guide. Regards,

  • Bare Metal Restore of AD

    I have inherited a domain setup at my new company and unfortunately a few of the 2008 R2 domain controllers only have 1 hard drive installed so if that drive fails the server is gone.  I am going to purchase a second hard drive so I can get this DC o

  • 6131 - Time setting

    Hi! I have a 6131 (RM-115) with FW V6.10 and s problem with time (zones). When I receive an SMS and look at the details, it says Time sent : 15:47 when actually the current time is 14:47. Recently we had the "move the clock one hour back" thing and I