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
    Regular Coder
    Join Date
    Aug 2005
    Posts
    257
    Thanks
    8
    Thanked 0 Times in 0 Posts

    validate form (some fields)

    how i can validate a form.

    if $pass is more than 5 characters return an alert message. Same function for white spaces in $pass and $username fields.

    Regards friends.

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,992
    Thanks
    203
    Thanked 2,536 Times in 2,514 Posts
    A variable name in JavaScript may only start with a letter, not a number or a $ sign.

    if (password.length > 5) {
    alert ("The maximum length is 5 characters);
    }

    If you want to delete spaces in a variable then:

    password = password.replace(/\s/g, "");


  •  

    Posting Permissions

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