Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Feb 2006
    Posts
    138
    Thanks
    11
    Thanked 0 Times in 0 Posts

    Creating a JS control for my form

    I need to control the form entry of people's phone numbers on my forms. Some people aren't entering one, some are entering too many or not enough numbers, etc.

    What I'd like to do is set it where the JS checks to see that 10 numbers have been entered, regardless of any additional characters (like -, (, ), space, etc..). If more or less than 10 numbers are entered, I would like it to display a message in a certain position below the form stating "Please enter your phone number in the proper format (xxx-xxx-xxxx)"

    Any help on how to get started doing this?

    Thanks!

  • #2
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,466
    Thanks
    3
    Thanked 495 Times in 482 Posts
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">
    
    <html>
    
    <head>
      <title></title>
    <script language="JavaScript" type="text/javascript">
    <!--
    
    function CkNumbers(obj,nu){
     var val=obj.value.replace(/\D/g,'');
     if (val.length!=nu){
      alert(nu+' Digits Required');
     }
    }
    //-->
    </script></head>
    
    <body>
    <input onblur="CkNumbers(this,10);" >
    </body>
    
    </html>
    Vic

    God Loves You and will never love you less.

    http://www.vicsjavascripts.org/Home.htm

    If my post has been useful please donate to http://www.operationsmile.org.uk/

  • #3
    Regular Coder
    Join Date
    Feb 2006
    Posts
    138
    Thanks
    11
    Thanked 0 Times in 0 Posts
    That works sort of, except after it displays the error message it still attempts to run the form target php file.. It also only stops the entry once, if you try it again, it accepts it...

  • #4
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,466
    Thanks
    3
    Thanked 495 Times in 482 Posts
    Code:
    <script language="JavaScript" type="text/javascript">
    <!--
    
    function CkNumbers(obj,nu){
     var val=obj.value.replace(/\D/g,'');
     if (val.length!=nu){
      alert(nu+' Digits Required');
      return false;
     }
     return true;
    
    }
    //-->
    </script>
    shows you how to verify the input
    will need to know more if to integrate in you code

    Please and Thank You are good
    Last edited by vwphillips; 08-02-2006 at 03:55 PM.
    Vic

    God Loves You and will never love you less.

    http://www.vicsjavascripts.org/Home.htm

    If my post has been useful please donate to http://www.operationsmile.org.uk/


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •