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 3 of 3

Thread: Form Validation

  1. #1
    New Coder
    Join Date
    Oct 2006
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Form Validation

    The script below shows an error if the digit count is less than four or more than 5 ...

    Code:
    	function validate2(form) {
    		if (form.pin.value.search( /^[0-9]{4}$/ ) == -1) {
    			alert('Please check your pin code and try again.');
    			form.pin.focus();
    			return false;
    		}
           }
    How can I change it so that it ONLY accepts 4, 5, or 6 digits long
    Last edited by holyearth; 07-10-2007 at 03:40 AM.

  • #2
    Regular Coder
    Join Date
    Feb 2005
    Posts
    679
    Thanks
    0
    Thanked 16 Times in 15 Posts
    To accept 4, 5, or 6 numbers try:
    Code:
    /^[0-9]{4,6}$/  or  /^\d{4,6}$/

  • #3
    New Coder
    Join Date
    Oct 2006
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks rwedge, that did it!


  •  

    Posting Permissions

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