SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Feb 2007
    Posts
    29
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Telephone Validation Script

    Hi,

    I have query on how to implement a telephone validation script into my html form. Someone have advised me to use the following script below (you can download to have a look for yourself):

    http://www.braemoor.co.uk/software/telnumbers.shtml

    My question is how am I going to integrate above script into my basic html form? Quite confusing really........

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,290
    Mentioned
    198 Post(s)
    Tagged
    3 Thread(s)

    phone number validation

    Are you already sanitizing the form's input with a script? It would probably be easiest to add the phone number validation script to that. If not, just route the phone number through the validation script at the same time.

  3. #3
    SitePoint Enthusiast
    Join Date
    Feb 2007
    Posts
    29
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What I am doing is, I copy and paste the whole scripts on top of my html form. But the only thing I don't know is how to really make it work.

    Below is my telephone form field which I wish to validate. Is there any things I need to add in to let the field communicate with the script?
    HTML Code:
    <label for="HomeTel" class="fixedwidth">Home Phone:</label>
              <input id="HomeTel" name="HomeTel" onkeyup="checkFieldBack(this)" />
    Below here is the top part of the script. Which of the following terms is the id that I need to put into the form field above?
    Code:
    function checkUKTelephone (telephoneNumber) {
    
      // Convert into a string and check that we were provided with something
      var telnum = telephoneNumber + " ";
      if (telnum.length == 1)  {
         telNumberErrorNo = 1;
         return false
      }
      telnum.length = telnum.length - 1;
    I am not very 100&#37; sure what I am asking actually. I hope someone understand what I meant.....

  4. #4
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,290
    Mentioned
    198 Post(s)
    Tagged
    3 Thread(s)

    phone number validation

    The way I put pages together is (a very stripped down example)
    HTML Code:
    <html>
    <head>
    <script type="text/javscript" src="external_js_file.js"></script>
    <script type="text/javscript">
    //"in page" javascript code here
    </script>
    </head>
    <body>
    <form>
    <input>
    </form>
    </body>
    </html>
    The "onkeyup" is the event, "checkFieldBack" is the function call, and "this" is a "magic" variable that passes the value of the input to the function as an argument.
    So as long as the "checkFieldBack" function is inside script tags it should work.
    But IMHO it may be better to include the script from an external file, ie.
    HTML Code:
    <script type="text/javscript" src="path/js_file.js"></script>
    for any file(s) you need to use.


Bookmarks

Posting Permissions

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