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 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Aug 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    JavaScript issue

    hi dears ,
    this is my first post in this forum ,

    the following code is working perfect except the last if statement .

    can anyone help plz

    <script type="text/javascript">
    function ValidateMobNumber(mobno) {
    var fld = document.getElementById(mobno);

    if (fld.value == "") {
    alert("You didn't enter a phone number.");
    fld.value = "";
    fld.focus();
    return false;
    }
    if (isNaN(fld.value)) {
    alert("The phone number contains illegal characters.");
    fld.value = "";
    fld.focus();
    return false;
    }
    if (!(fld.value.length == 8)) {
    alert("Please enter 8 digit mobile no.");
    fld.value = "";
    fld.focus();
    return false;
    }
    if (fld.charAt(0)!="9"){
    alert("Mobile No has to start with 9");
    fld.value = "";
    fld.focus();
    return false;
    }


    }



    </script>

    your kind support highly appreciated

  • #2
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,495
    Thanks
    3
    Thanked 500 Times in 487 Posts
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    
    <head>
      <title></title>
    <script type="text/javascript">
    function ValidateMobNumber(mobno) {
    var fld = document.getElementById(mobno);
    
    if (fld.value == "") {
    alert("You didn't enter a phone number.");
    fld.value = "";
    fld.focus();
    return false;
    }
    if (isNaN(fld.value)) {
    alert("The phone number contains illegal characters.");
    fld.value = "";
    fld.focus();
    return false;
    }
    if (!(fld.value.length == 8)) {
    alert("Please enter 8 digit mobile no.");
    fld.value = "";
    fld.focus();
    return false;
    }
    if (fld.value.charAt(0)!="9"){
    alert("Mobile No has to start with 9");
    fld.value = "";
    fld.focus();
    return false;
    }
    
    }
    
    
    
    </script></head>
    
    <body>
    
    </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/


  •  

    Posting Permissions

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