SitePoint Sponsor

User Tag List

Page 3 of 5 FirstFirst 12345 LastLast
Results 51 to 75 of 120
  1. #51
    SitePoint Addict
    Join Date
    Jul 2011
    Location
    Hyderabad,India.
    Posts
    327
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    username should be maximum of 12 to 15 characters should have only one special character(.,_,-)
    some valid examples ravikumar_951 and ravikumar.951

  2. #52
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,678
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by ravi951 View Post
    username should be maximum of 12 to 15 characters should have only one special character(.,_,-)
    some valid examples ravikumar_951 and ravikumar.951
    That didn't answer the question. Want to try again?

    How many characters will you allow after the separator? Current examples show 3, but will you allow that to vary?
    Or, does the number of characters after the separator not matter, so long as the total length of the username is within the 15 limit?
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #53
    SitePoint Addict
    Join Date
    Jul 2011
    Location
    Hyderabad,India.
    Posts
    327
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yes it does not matter how many characters after separator but maximum length should be 15

  4. #54
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,678
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by ravi951 View Post
    yes it does not matter how many characters after separator but maximum length should be 15
    Right, so the regular expression doesn't need to have any length restrictions, since you are already doing that in the code.

    So it seems that the regular expression that achieves the needed requirements is:
    /^[a-z0-9]+[_.-][a-z0-9]+$/
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  5. #55
    SitePoint Addict
    Join Date
    Jul 2011
    Location
    Hyderabad,India.
    Posts
    327
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    still now also that regular expression is not working.same problem if we give valid expression also it is not accepting.

  6. #56
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,678
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by ravi951 View Post
    still now also that regular expression is not working.same problem if we give valid expression also it is not accepting.
    Well there is nothing wrong with the regular expression. let's look further.

    What is the code that you are currently using to use the regular expression to test the username?
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  7. #57
    SitePoint Addict
    Join Date
    Jul 2011
    Location
    Hyderabad,India.
    Posts
    327
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    here is my code for username.

    function checkName(form) /* for real name verification */
    {
    var re =/^[a-z0-9]+[_.-][a-z0-9]+$/;
    var isCorrectFormat = re.test(form);
    if (isCorrectFormat)
    {
    alert("Invalid characters in username. It can only contain._ and-");
    return false;
    }
    else if (form.realname.value == '')
    {
    alert('Error: Username cannot be blank!');
    form.realname.focus();
    return false;
    }
    else if(form.realname.value.length < 4)
    {
    alert("UserName should be atleast 4 characters long");
    return false;
    }


    return true;
    }

  8. #58
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,678
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by ravi951 View Post
    here is my code for username.
    Look at what you are testing. There you will find the problem.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  9. #59
    SitePoint Addict
    Join Date
    Jul 2011
    Location
    Hyderabad,India.
    Posts
    327
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i have tested this code many times but i am unable to figure it out what went
    wrong

  10. #60
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,678
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by ravi951 View Post
    i have tested this code many times but i am unable to figure it out what went
    wrong
    Once again, look at what you are testing.

    Look, here it is.

    Code:
    var isCorrectFormat = re.test(form);
    There you will find the problem. Look, I'll color it in red for you.

    Code:
    var isCorrectFormat = re.test(form);
    That is what is causing your problem.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  11. #61
    SitePoint Addict
    Join Date
    Jul 2011
    Location
    Hyderabad,India.
    Posts
    327
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    why is wrong to include a form name in testing...
    then what to replace it with..

  12. #62
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,678
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by ravi951 View Post
    why is wrong to include a form name in testing...
    then what to replace it with..
    What are you supposed to be testing there?
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  13. #63
    SitePoint Addict
    Join Date
    Jul 2011
    Location
    Hyderabad,India.
    Posts
    327
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    username should be accepted if valid or else display error message

  14. #64
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,678
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by ravi951 View Post
    username should be accepted if valid or else display error message
    Right, so you need to test the username instead. Look at other parts of your code where you perform other checks on the username. There you will see how you should be referring to the value of the username.
    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)
    i have checked extensively but i am unable to find the error.

  16. #66
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,678
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by ravi951 View Post
    i have checked extensively but i am unable to find the error.
    Let's take this more slowly then.

    Look at other parts of your code where you perform other checks on the username.
    Can you find a line in your code where the username is being checked for something else?
    Can you show us that line?
    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)
    i have been checking username for 3 conditions

    1)it should accept special characters
    2)username should not be empty
    3)username should be more than 4 characters


    function checkName(form) /* for real name verification */
    {
    var re =/^[a-z0-9]+[_.-][a-z0-9]+$/; /* for accepting only alphabets,digits and 3 special characters */
    var isCorrectFormat = re.test(form);
    if (!isCorrectFormat)
    {
    alert("Invalid characters in username. It can only contain._ and-");
    return false;
    }
    else if (form.realname.value == '')
    {
    alert('Error: Username cannot be blank!');
    form.realname.focus();
    return false;
    }
    else if(form.realname.value.length < 4)
    {
    alert("UserName should be atleast 4 characters long");
    return false;
    }

    return true;
    }
    this is the main function for checking the above conditions....

    the below function is the overall function checking all conditions.....
    function validate()
    {
    var form = document.forms['form'];

    if (!checkName(form) || !checkEmail(form) || !validatePwd(form) || !validPhone(form))
    {
    return false;
    }

    return true;
    }

  18. #68
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,678
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by ravi951 View Post
    i have been checking username for 3 conditions
    Want to try that again?

    Can you find a line in your code where the username is being checked for something else?
    Can you show us that one line?
    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)
    except in the checkName(form) function i have not used username function any where in the program

  20. #70
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,678
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by ravi951 View Post
    except in the checkName(form) function i have not used username function any where in the program
    Yes you have. Use a word-search if you need to.
    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 over all code
    check it once i have never used other than username in checkName(form)
    function.
    <html>
    <head>
    <meta charset="utf-8">
    <title>Validation using JavaScript</title>
    <script type="text/javascript">
    function checkName(form) /* for real name verification */
    {

    var re =/^[a-z0-9]+[_.-][a-z0-9]+$/;
    var isCorrectFormat = re.test(form);
    if (!isCorrectFormat)
    {
    alert("Invalid characters in username. It can only contain._ and-");
    return false;
    }
    else if (form.realname.value == '')
    {
    alert('Error: Username cannot be blank!');
    form.realname.focus();
    return false;
    }
    else if(form.realname.value.length < 4)
    {
    alert("UserName should be atleast 4 characters long");
    return false;
    }

    return true;
    }

    else if (form.realname.value == '')
    {
    alert('Error: Username cannot be blank!');
    form.realname.focus();
    return false;
    }
    else if(form.realname.value.length < 4)
    {
    alert("UserName should be atleast 4 characters long");
    return false;
    }

    return true;
    }

    function checkEmail(form) /* for email validation */
    {
    if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(form.email.value))
    {
    return true;
    }

    alert('Invalid E-mail Address! Please re-enter.');
    return false;
    }

    function validatePwd(form) /* password & retype-password verification */
    {
    var invalid = ' ';
    minLength = 6;
    var pw1 = form.password.value;
    var pw2 = form.password2.value;


    if (pw1 == '' || pw2 == '')
    {
    alert('Please enter your password twice.');
    return false;
    }


    if (form.password.value.length < minLength)
    {
    alert('Your password must be at least ' + minLength + ' characters long. Try again.');
    return false;
    }

    if (document.form.password.value.indexOf(invalid) > -1)
    {
    alert('Sorry, spaces are not allowed.');
    return false;
    }
    else
    {
    if (pw1 != pw2)
    {
    alert('You did not enter the same new password twice. Please re-enter your password.');
    return false;
    }
    else
    {
    alert('Passwords Match.');
    return false;
    }

    return false;
    }
    }

    function validPhone(form) /* phone no validation */
    {
    var valid = '0123456789';
    phone = form.phoneno.value;

    if (phone == '')
    {
    alert('This field is required. Please enter phone number');
    return false;
    }

    if (!phone.length > 1 || phone.length < 10)
    {
    alert('Invalid phone number length! Please try again.');
    return false;
    }

    for (var i = 0; i < phone.length; i++)
    {
    temp = '' + phone.substring(i, i + 1);

    if (valid.indexOf(temp) == -1)
    {
    alert('Invalid characters in your phone. Please try again.');
    return false;
    }
    }

    return true;
    }

    function validate()
    {
    var form = document.forms['form'];

    if (!checkName(form) || !checkEmail(form) || !validatePwd(form) || !validPhone(form))
    {
    return false;
    }

    return true;
    }
    </script>
    </head>
    <body>

    <form action="" method="post" name="form" onsubmit="return validate()">
    User Name : <input type="text" name="realname" size="19">
    <br>
    E-Mail : <input type="text" name="email" size="25">
    <br>
    Password : <input type="password" name="password" maxlength="12" size="25">
    <br>
    Retype password: <input type="password" name="password2" maxlength="12" size="25">
    <br>
    PhoneNo : <input type="phoneno" name="phoneno" maxlength="10" size="25">
    <br>
    <input type="submit" value="Submit">
    </form>

    </body>
    </html>

  22. #72
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,678
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by ravi951 View Post
    below is my over all code
    check it once i have never used other than username in checkName(form)
    function.
    It is in that function that I am meaning.

    To continue on with helping you to find the error, let's look at where the username is being used correctly.

    Find a line in that function where the username is being checked?
    Can you show us one of those lines?
    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)
    below is the function i am using to checking the conditions

    var re =/^[a-z0-9]+[_.-][a-z0-9]+$/;
    var isCorrectFormat = re.test(form);
    if (!isCorrectFormat)
    {
    alert("Invalid characters in username. It can only contain._ and-");
    return false;
    }

  24. #74
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,678
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by ravi951 View Post
    below is the function i am using to checking the conditions

    var re =/^[a-z0-9]+[_.-][a-z0-9]+$/;
    var isCorrectFormat = re.test(form);
    if (!isCorrectFormat)
    {
    alert("Invalid characters in username. It can only contain._ and-");
    return false;
    }
    That is where you are trying to check the types of characters in the username.

    There are other parts of the checkName function that check whether the username is blank, and that checks the length of the username.

    So, find a line in that function where the username is being checked.
    Can you show us one of those lines?
    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)
    username should not be blank

    else if (form.realname.value == '')
    {
    alert('Error: Username cannot be blank!');
    form.realname.focus();
    return false;
    }


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
  •