[thelist] RegEx problem again
Simon Perry
thelist at si-designs.co.uk
Mon Aug 8 11:26:56 CDT 2005
Kowalkowski, Lee (ASPIRE) wrote:
>>-----Original Message-----
>>From: Tom Dell'Aringa [mailto:pixelmech at yahoo.com]
>>var namematch = /^[a-zA-Z]{3,}$/.test(nametext.value);
>>namematch = (namematch || /^[a-zA-Z\*]{4,}$/.test(nametext.value));
>>
>>Which worked just fine, till we realized we need to allow one
>>or more SPACES as well! How do you
>>add a space to the pattern? (and allow for as many spaces as
>>they like?)
>>
>>
>
>Just add a space to the character sets, so [a-zA-Z] becomes [a-zA-Z ]. Note
>the space before the closing square bracket.
>
>
>
That wont work as you will no longer ensure a minimum of 3 alpha chars
with or without the asterisk "a b" and "a b*" will now validate.
The original may have a problem as well as "****" will validate. I
didn't follow the original thread but I presume you want one or more
wild card * to be allowed and a minimum of 3 alpha chars?
How about this
testString=nametext.value.replace(/ /g,"");// remove spaces from our
test string as these are allowed
testString=testString.replace(/\*/g,"");// remove all asterisk from our
test string as they are allowed too
namematch=/^([A-Za-z]{3,})$/.test(testString);//a match is returned if 3
or more alpha chars are present
if(namematch==true)
{
//pass the original nametext.value to your next step as it validates
}
else
{
//warn user the input doesn't validate
}
Simon
More information about the thelist
mailing list