Results 1 to 4 of 4

Thread: validation help

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 1999
    Location
    ma,usa
    Posts
    485

    validation help

    Hi

    I need to validate that a textbox has the following format using javascript. Can anyone help me out?

    textbox must have format "00000-0000" or "00000-" anything else must send: alert ('Format is unacceptable. Please insure you have used five digits followed by a dash or nine digits seperated by a dash in the sixth position');

    Thanks in advance
    Joey O.

  2. #2
    Frenzied Member DeadEyes's Avatar
    Join Date
    Jul 2002
    Posts
    1,196
    this is crude and th regexp should be improved upon but
    i think it will work
    Code:
    function test(){
    	var str = new String(document.frm.txt.value);
    	if( ((str.search(/\d{5}\-/)==0) && str.length == 6) || ((str.search(/\d{5}\-\d{4}/)==0) && str.length== 10) ){
    		alert('match');
    	}
    	else{
    		alert('nomatch');
    	}
    	return true;
    }

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 1999
    Location
    ma,usa
    Posts
    485
    Awsome - Thanks!

    One question: Is d an object to denote 'digits' or just a placeholder for the string?

  4. #4
    Frenzied Member DeadEyes's Avatar
    Join Date
    Jul 2002
    Posts
    1,196
    search uses regular expressions which have a special syntax
    \d = match digit [0-9]
    \w = would mean match alphanumeric [a-z][A-Z][0-9]
    {5} means match 5 of them

Posting Permissions

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



Click Here to Expand Forum to Full Width