[thelist] numeric only regex? [ and one more perhaps?]
Kowalkowski, Lee (ASPIRE)
lee.kowalkowski at hmrcaspire.com
Wed Aug 3 08:12:34 CDT 2005
> -----Original Message-----
> From: Tom Dell'Aringa [mailto:pixelmech at yahoo.com]
> The other one is the customer NAME. The requirements for this one are:
>
> - Minimum 3 characters
> - Alpha only
> - We must allow a wildcard character of "*"
>
> So valid would be: abc, abc*, abcde etc
> and invalid input: ab*, ab, 1a*, 1a
>
> For that we are using:
> ---
> if (nametext.value.length > 0) {
> var noWildCards = nametext.value.split("*");
> if (noWildCards[0].length < 3) {
> alert("The customer search criteria must have at
> least 3 characters (and may also have
> optional wildcards).\nYou entered: "+nametext.value);
> return false;
> }
> }
> --
>
> It seems to work, but I'm wondering if there is a better
> regex way to do it instead...
I couldn't see a check for non-alphabetic characters in your sample.
Using regex:
if(!/^[a-z]{3}[a-z]*[*]?$/i.test(nametext.value))
{
// error.
}
... assuming the wildcard must be at the end. Can the wildcard be anywhere,
even at the start?
-- LK
===========================================================
Our e-mail domain has now changed from iraspire.com to hmrcaspire.com. Please update your address books.
===========================================================
More information about the thelist
mailing list