SitePoint Sponsor

User Tag List

Page 3 of 5 FirstFirst 12345 LastLast
Results 51 to 75 of 125
  1. #51
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,696
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by ravi951 View Post
    then why my script is not executing...
    whats the problem...
    Aha, that is the right question to ask.

    If the script has a problem, such as an expected HTML element not being there, thr script will fail and stop executing. It will not return false to prevent the form from submitting, which means that the onsubmit event will continue on and submit, even though there was a problem.

    The problem that I see occurring, is that the script is attempting to access a field named "password2". The currently has a field with the name "repassword", so you should update the form so that it meets up with the requirements of the script.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  2. #52
    SitePoint Addict
    Join Date
    Jul 2011
    Location
    Hyderabad,India.
    Posts
    327
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you are telling me to update "repassword" to "password2" in html script right..
    will that solve.......

  3. #53
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,696
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by ravi951 View Post
    you are telling me to update "repassword" to "password2" in html script right..
    will that solve.......
    Yes, that will solve the problem.

    Your jsFiddle has config issues also getting in your way.

    You need also to:

    1. Change onLoad to no wrap (body preferably)
    2. Change MooTools to No library
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  4. #54
    SitePoint Addict
    Join Date
    Jul 2011
    Location
    Hyderabad,India.
    Posts
    327
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    then my messagesnew.js will be the below code .....is that so..

    // form validation function //
    Code:
    function validate() {
      hasFocus = false;
      var form = document.forms['form'];
      var ary=[checkName,checkEmail,validatePwd,validPhone];
      var rtn=true;
      var z0=0;
      for (var z0=0;z0<ary.length;z0++) {
        if (!ary[z0](form)) {
          rtn=false;
        }
      }
      return rtn;
    }
       function checkName(form) 
       {
        var eobj = document.getElementById('realnameerror');
        var sRealName = form.realname.value;
        var oRE = /^[a-z0-9]+[_.-]?[a-z0-9]+$/i;
        var error = false;
        eobj.innerHTML = '';
        if (sRealName == '') 
         {
            error = 'Error: Username cannot be blank!';
         }
        else if (sRealName.length < 4) 
        {
            error = "UserName should be atleast 4 characters long";
        }
        else if (!oRE.test(sRealName)) 
        {
            error = "Incorrect format.";
        }
        if (error) 
        {
            if (hasFocus == false) 
             {
                form.realname.focus();
                hasFocus = true;
             }
            eobj.innerHTML = error;
            return false;
        }
        return true;
    }
     
    function checkEmail(form)          /* for email validation */ 
    {
        var eobj = document.getElementById('emailerror');
        eobj.innerHTML = '';
        var error = false;
        if(form.email.value.length == 0) 
        {
            error = 'Please enter email.';
        } else if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(form.email.value)) 
           {
            return true;
           } else 
              {
            error = 'Invalid E-mail Address! Please re-enter.';
              }
        if (error) 
         {
            eobj.innerHTML = error;
            if (!hasFocus) 
              {
                form.email.focus();
                hasFocus = true;
              }
            return false;
         }
         return true;
    }
    
    function validatePwd(form)          /* password & retype-password verification */ 
    {
        var eobj1 = document.getElementById('passworderror');
        var eobj2 = document.getElementById('password2error');
        var minLength = 6;
        var invalid = ' ';
        var pw1 = form.password.value;
        var pw2 = form.password2.value;
        var error = false;
        eobj1.innerHTML = '';
        eobj2.innerHTML = '';
        if (pw1.length < 1) 
    	{
           error = 'Please enter your password.';
        }
    
        else if (pw1.length < minLength) 
    	{
            error = 'Your password must be at least ' + minLength + ' characters long. Try again.';
        }
    
        else if (pw1.indexOf(invalid) > -1) 
    	{
            error = 'Sorry, spaces are not allowed.';
        }
    
        else if (pw2.length == 0) 
    	{
            error = 'Please retype password.';
            if (!hasFocus)
    		{
                form.password2.focus();
                hasFocus = true;
            }
            eobj2.innerHTML = error;
            return false;
        }
        if (error) 
    	{
            if (!hasFocus) 
    		{
                form.password.focus();
                hasFocus = true;
            }
            eobj1.innerHTML = error;
            return false;
        }
    
        if (pw1 != pw2) 
    	{
            eobj2.innerHTML = ' passwords not matching.Please re-enter your password.';
            if (!hasFocus) 
    		{
                form.password2.focus();
                hasFocus = true;
            }
            return false;
        }
        return true;
    }
    
    function validPhone(form)              /* phone no validation */ 
    {
        var eobj = document.getElementById('phonenoerror');
        var valid = '0123456789';
        var phone = form.phoneno.value;
        var error = false;
        var i = 0;
        var temp;
        eobj.innerHTML = '';
        if (phone == '') 
    	{
            error = 'This field is required. Please enter phone number';
        }
        else if (!phone.length > 1 || phone.length < 10) 
    	{
            error = 'Invalid phone number length! Please try again.';
        }
        else 
    	{
            for (i = 0; i < phone.length; i++) 
    		{
                temp = '' + phone.substring(i, i + 1);
                if (valid.indexOf(temp) == -1) 
    			{
                    error = 'Invalid characters in your phone. Please try again.';
                }
            }
        }
        if (error) 
    	{
            if (!hasFocus) 
    		{
                form.phoneno.focus();
                hasFocus = true;
            }
            eobj.innerHTML = error;
            return false;
        }
        return true;
    }
    // START OF MESSAGE SCRIPT //
    
    var MSGTIMER = 20;
    var MSGSPEED = 5;
    var MSGOFFSET = 3;
    var MSGHIDE = 3;
    
    // build out the divs, set attributes and call the fade function //
    function inlineMsg(target,string,autohide) {
      var msg;
      var msgcontent;
      if(!document.getElementById('msg')) {
        msg = document.createElement('div');
        msg.id = 'msg';
        msgcontent = document.createElement('div');
        msgcontent.id = 'msgcontent';
        document.body.appendChild(msg);
        msg.appendChild(msgcontent);
        msg.style.filter = 'alpha(opacity=0)';
        msg.style.opacity = 0;
        msg.alpha = 0;
      } else {
        msg = document.getElementById('msg');
        msgcontent = document.getElementById('msgcontent');
      }
      msgcontent.innerHTML = string;
      msg.style.display = 'block';
      var msgheight = msg.offsetHeight;
      var targetdiv = document.getElementById(target);
      targetdiv.focus();
      var targetheight = targetdiv.offsetHeight;
      var targetwidth = targetdiv.offsetWidth;
      var topposition = topPosition(targetdiv) - ((msgheight - targetheight) / 2);
      var leftposition = leftPosition(targetdiv) + targetwidth + MSGOFFSET;
      msg.style.top = topposition + 'px';
      msg.style.left = leftposition + 'px';
      clearInterval(msg.timer);
      msg.timer = setInterval("fadeMsg(1)", MSGTIMER);
      if(!autohide) {
        autohide = MSGHIDE;  
      }
      window.setTimeout("hideMsg()", (autohide * 1000));
    }
    
    // hide the form alert //
    function hideMsg(msg) {
      var msg = document.getElementById('msg');
      if(!msg.timer) {
        msg.timer = setInterval("fadeMsg(0)", MSGTIMER);
      }
    }
    
    // face the message box //
    function fadeMsg(flag) {
      if(flag == null) {
        flag = 1;
      }
      var msg = document.getElementById('msg');
      var value;
      if(flag == 1) {
        value = msg.alpha + MSGSPEED;
      } else {
        value = msg.alpha - MSGSPEED;
      }
      msg.alpha = value;
      msg.style.opacity = (value / 100);
      msg.style.filter = 'alpha(opacity=' + value + ')';
      if(value >= 99) {
        clearInterval(msg.timer);
        msg.timer = null;
      } else if(value <= 1) {
        msg.style.display = "none";
        clearInterval(msg.timer);
      }
    }
    
    // calculate the position of the element in relation to the left of the browser //
    function leftPosition(target) {
      var left = 0;
      if(target.offsetParent) {
        while(1) {
          left += target.offsetLeft;
          if(!target.offsetParent) {
            break;
          }
          target = target.offsetParent;
        }
      } else if(target.x) {
        left += target.x;
      }
      return left;
    }
    
    // calculate the position of the element in relation to the top of the browser window //
    function topPosition(target) {
      var top = 0;
      if(target.offsetParent) {
        while(1) {
          top += target.offsetTop;
          if(!target.offsetParent) {
            break;
          }
          target = target.offsetParent;
        }
      } else if(target.y) {
        top += target.y;
      }
      return top;
    }
    // preload the arrow //
    if(document.images) {
      arrow = new Image(7,80); 
      arrow.src = "images/msg_arrow.gif"; 
    }
    }

  5. #55
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,696
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by ravi951 View Post
    then my messagesnew.js will be the below code .....is that so..
    No it will not. The JavaScript code should not change at all from that which is in your first post to this thread.

    It is the HTML code for the form that should be updated, to bring it in line with what is expected by the script.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  6. #56
    SitePoint Addict
    Join Date
    Jul 2011
    Location
    Hyderabad,India.
    Posts
    327
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i have updated by changing "repassword" to "password2" in my login.html......
    but also not executing......
    i have shown in my jsfiddle...as below
    http://jsfiddle.net/ravi951/NfjwK/7/

    but also not executing.......

  7. #57
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,696
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by ravi951 View Post
    i have updated by changing "repassword" to "password2" in my login.html......
    but also not executing......
    i have shown in my jsfiddle...as below
    http://jsfiddle.net/ravi951/NfjwK/7/

    but also not executing.......
    The JavaScript used in that fiddle is still not the script that you used in your first post.

    As soon as you use the JavaScript from your first post, it will work good and properly.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  8. #58
    SitePoint Addict
    Join Date
    Jul 2011
    Location
    Hyderabad,India.
    Posts
    327
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yes it is executing but in out the login form fields are not in correct order.
    "retype password" field must be in single line and all the colons must be one below the another......
    how to display that.......

    below is my updated fiddle
    http://jsfiddle.net/ravi951/NjW9Q/4/

    u can check output there....

  9. #59
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,696
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by ravi951 View Post
    yes it is executing but in out the login form fields are not in correct order.
    "but in out" ???
    Can you please explain further?

    Quote Originally Posted by ravi951 View Post
    "retype password" field must be in single line
    You should be able to adjust CSS width of the wrapper, from a width of 600 to a width of 700 instead.

    Quote Originally Posted by ravi951 View Post
    and all the colons must be one below the another......
    Pardon? Colons, like these?
    :
    :
    :
    :

    What do you mean?
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  10. #60
    SitePoint Addict
    Join Date
    Jul 2011
    Location
    Hyderabad,India.
    Posts
    327
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    like in many login forms....

    username :textbox
    email id : textbox
    password : textbox
    retype password : textbox
    phone no : textbox

    in my original form page my field retype password field is not in a single line....
    and alll fields should be like above given shown ......

  11. #61
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,696
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by ravi951 View Post
    like in many login forms....
    I am assuming that you mean like this:

    Code:
    username            : textbox
    email id            : textbox
    password            : textbox
    retype password     : textbox
    phone no            : textbox
    You can achieve that by removing the colon from inside of the label, and putting it after the label.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  12. #62
    SitePoint Addict
    Join Date
    Jul 2011
    Location
    Hyderabad,India.
    Posts
    327
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    do u mean like this......
    <label for="name">User Name</label>:
    <input type="text" name="realname" id="name" />
    <span id="realnameerror"></span>

    no it is not working......
    also my password field is displaying what i gave..it is not hiding the contents
    also phone no field should be restricted to 10 digits but it is acceoting any no of digits....
    what is wrong.......

  13. #63
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,696
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by ravi951 View Post
    why my password field is displaying passwords which i given
    Have you specified in the HTML type attribute that the type of field should be password?

    Quote Originally Posted by ravi951 View Post
    also the phone no field is accepting phone no more than 10 digits
    Currently the script has the invalid length if the length is less than 10. If you want to change the error from less-than 10 to greater-than 10, then do that.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  14. #64
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,696
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by ravi951 View Post
    do u mean like this......
    <label for="name">User Name</label>:
    <input type="text" name="realname" id="name" />
    <span id="realnameerror"></span>
    No, I think that CSS has a before selector, but the people in the CSS forum would be able to help you more with how you can adjust the presentation of your HTML so that it looks how you want it to look.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  15. #65
    SitePoint Addict
    Join Date
    Jul 2011
    Location
    Hyderabad,India.
    Posts
    327
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yes in my html page i clearly mentioned that...
    below is my login page
    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">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Dynamic Inline Form Validation Demo</title>
    <link rel="stylesheet" type="text/css" href="messages1.css" />
    <script type="text/javascript" src="messages1.js"></script>
    </head>
    <body>
    <div id="wrapper">
      <form name="form" id="form" class="form" action="success1.html" onsubmit="return validate(this)" method="post">
        <label for="name">User Name</label>:
        <input type="text" name="realname" id="name" />
    	<span id="realnameerror"></span>
        
    	<label for="email">Email Id</label>:
        <input type="text" name="email" id="email" />
    	<span id="emailerror"></span>
        
    	<label for="password">Password</label>:
        <input type="text" name="password" id="password" />
    	<span id="passworderror"></span>
    	
        <label for="repassword">Retype Password</label>:
        <input type="text" name="password2" id="password2" />
    	<span id="password2error"></span>
    	
    	<label for="phoneno">Phone no</label>:
        <input type="text" name="phoneno" id="phoneno" />
    	<span id="phonenoerror"></span>
    	
    	<input type="submit" value="Submit" class="submit" />
      </form>
    </div>
    </body>
    </html>
    i have changed the phone no length to greater than 10 but it is not accepting.,.......
    below is what i changed.....
    else if (!phone.length > 1 || phone.length > 10)

  16. #66
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,696
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by ravi951 View Post
    i have changed the phone no length to greater than 10 but it is not accepting.,.......
    below is what i changed.....
    else if (!phone.length > 1 || phone.length > 10)
    Your link to the recent update doesn't show the changed condition. What is the link that shows it?
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  17. #67
    SitePoint Addict
    Join Date
    Jul 2011
    Location
    Hyderabad,India.
    Posts
    327
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    this is my updated link......
    http://jsfiddle.net/ravi951/gYyAQ/1/
    i have changed to > ......

  18. #68
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,696
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by ravi951 View Post
    this is my updated link......
    http://jsfiddle.net/ravi951/gYyAQ/1/
    i have changed to > ......
    It seems to work for me. A phone number that is more than 10 characters in length (11 characters or greater) results in the error message.

    If you still have trouble, perhaps you could consent to allow us the knowledge of what it is with which the testing is being performed.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  19. #69
    SitePoint Addict
    Join Date
    Jul 2011
    Location
    Hyderabad,India.
    Posts
    327
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    actually phone no should be of exactly 10 digits only.not greater than
    or less than 10....
    if we are giving more than 10 digits it should stop taking the input.
    after accepting 10 digits it should not accept even one digit also...
    if we give less than 10 it must ask for 10 only....

  20. #70
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,696
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by ravi951 View Post
    actually phone no should be of exactly 10 digits only.not greater than
    or less than 10....
    The requirements continue to change.

    Instead of this which checks if the length is 1 or greater than 10

    Code:
    else if (!phone.length > 1 || phone.length > 10)
    You need to instead check if the phone length is different from 10

    Code:
    else if (phone.length <> 10)
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  21. #71
    SitePoint Addict
    Join Date
    Jul 2011
    Location
    Hyderabad,India.
    Posts
    327
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    below is my jsfiddle which i updated for phone.length <>10
    but also not executing.....
    given link below......

    http://jsfiddle.net/ravi951/gYyAQ/3/

    i have the similar code with out CSS which accepts exactly 10 digits...
    below is the code saves as new.html
    Code:
    <html>
    <head>
    <meta charset="utf-8">
    <title>Validation using JavaScript</title>
    <script type="text/javascript">
    
    var hasFocus = false;
    
     function checkName(form)
    {
      var eobj=document.getElementById('realnameerror');
      var sRealName = form.realname.value;
      var oRE = /^[a-z0-9]+[_.-]?[a-z0-9]+$/i;
      var error=false;
      eobj.innerHTML='';
      if (sRealName == '') 
      {
       error='Error: Username cannot be blank!';
      }
      else if (sRealName.length < 4) 
      {
        error="UserName should be atleast 4 characters long";
      }
      else if (!oRE.test(sRealName))
      {
       error="Incorrect format.";
      }
      if (error)
    {
       if (hasFocus == false) 
       {
         form.realname.focus();
         hasFocus = true;
       } 
       eobj.innerHTML=error;
       return false;
      }
      return true;
     }
    
    function checkEmail(form)          /* for email validation */
    {
     var eobj=document.getElementById('emailerror');
     eobj.innerHTML='';
     var error = false;
      if (form.email.value.length == 0) 
      {
        error = 'Please enter email.';
      } else if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(form.email.value))
     {
      return true;
     } else 
     {
       error = 'Invalid E-mail Address! Please re-enter.';
     }
     if (error) 
    {
       eobj.innerHTML=error;
       if (!hasFocus) 
       {
         form.email.focus();
         hasFocus = true;
       } 
       return false;
     }
    
     return true;
    }
    
    function validatePwd(form)          /* password & retype-password verification */
    {       
     var eobj1=document.getElementById('passworderror');
     var eobj2=document.getElementById('password2error');
     var minLength=6;
     var invalid=' ';
     var pw1=form.password.value;
     var pw2=form.password2.value;
     var error=false;
     eobj1.innerHTML='';
     eobj2.innerHTML='';
     if (pw1.length<1)
     {
      error='Please enter your password.';
     }
     else if (pw1.length < minLength)
     {
      error='Your password must be at least ' + minLength + ' characters long. Try again.';
     }
     else if (pw1.indexOf(invalid) > -1)
     {
      error='Sorry, spaces are not allowed.';
     } 
    else if (pw2.length == 0) 
    {
      error='Please retype password.';
       if (!hasFocus) 
       {
         form.password2.focus();
         hasFocus = true;
       } 
      eobj2.innerHTML=error;
      return false;
     }
     if (error)
     {
       if (!hasFocus) 
       {
         form.password.focus();
         hasFocus = true;
       } 
        eobj1.innerHTML=error;
      return false
     }
     if (pw1 != pw2)
     {
      eobj2.innerHTML=' passwords not matching.Please re-enter your password.';
       if (!hasFocus) 
       {
         form.password2.focus();
         hasFocus = true;
       } 
      return false;
     }
     return true;
    }
    
    function validPhone(form)              /* phone no validation */
    {          
     var eobj=document.getElementById('phonenoerror');
     var valid = '0123456789';
     var phone = form.phoneno.value;
     var error=false;
     var i=0;
     var temp;
     eobj.innerHTML='';
     if (phone == '')
     {
      error='This field is required. Please enter phone number';
     }
     else if (!phone.length > 1 || phone.length < 10)
     {
      error='Invalid phone number length! Please try again.';
     }
     else 
     {
      for (i=0; i < phone.length; i++)
     {
       temp = '' + phone.substring(i, i + 1);
       if (valid.indexOf(temp) == -1)
        {
        error='Invalid characters in your phone. Please try again.';
        }
      }
     }
     if (error)
     {
       if (!hasFocus) 
       {
         form.phoneno.focus();
         hasFocus = true;
       } 
      eobj.innerHTML=error;
      return false;
     }
     return true;
    }
    
    function validate() 
     {
      hasFocus = false;
     var form = document.forms['form'];
     var ary=[checkName,checkEmail,validatePwd,validPhone];
     var rtn=true;
     var z0=0;
     for (var z0=0;z0<ary.length;z0++)
    {
      if (!ary[z0](form))
      {
        rtn=false;
      }
     }
     return rtn;
    }
    </script>
    </head>
    <body>
    
    <form action="" method="post" name="form" onsubmit="return validate()">
       User Name : <input type="text" name="realname" size="19"><span id="realnameerror" ></span>
        <br>
       E-Mail    : <input type="text" name="email" size="25"><span id="emailerror" ></span>
        <br>
       Password  : <input type="password" name="password" maxlength="12" size="25"><span id="passworderror" ></span>
        <br>
       Retype password: <input type="password" name="password2" maxlength="12" size="25"><span id="password2error" ></span>
        <br>
       PhoneNo   : <input type="phoneno" name="phoneno" maxlength="10" size="25"><span id="phonenoerror" ></span>
        <br>
        <input type="submit" value="Submit">
    </form>
    </body>
    </html>
    i have taken the same code forom here but it is not accepting......

  22. #72
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,696
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by ravi951 View Post
    below is my jsfiddle which i updated for phone.length <>10
    Sorry, I'm still getting over a cold. It's !== instead of <>
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  23. #73
    SitePoint Addict
    Join Date
    Jul 2011
    Location
    Hyderabad,India.
    Posts
    327
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    in the html page i lastly posted to you will not accept more than 10 digits.even if we try to give more than 10 digits also it stops......
    but your code !== is accepting more than 10 digits....
    i dont want to exceed more than 10 digits.....
    how to do...

  24. #74
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,696
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by ravi951 View Post
    in the html page i lastly posted to you will not accept more than 10 digits.even if we try to give more than 10 digits also it stops......
    but your code !== is accepting more than 10 digits....
    i dont want to exceed more than 10 digits.....
    how to do...
    Update the fiddle and give us the link.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  25. #75
    SitePoint Addict
    Join Date
    Jul 2011
    Location
    Hyderabad,India.
    Posts
    327
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    k here is the html link for phone no accepting 10 digits.....

    http://jsfiddle.net/ravi951/5rpYJ/1/

    from yhat code only i have taken this code.......


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
  •