"David" <no****@nospanm.comwrote in message
news:km**************@news-server.bigpond.net.au...
>I forgot to mention as well that it was allowing whitespace. Which i did
not
want.
all i want is A-Z regardless of case. and Numbers. No other characters.
And
start with a letter.
"David" <no****@nospanm.comwrote in message
news:q9**************@news-server.bigpond.net.au...
>Help how can I force the variable to start with a character.
I dont want it to start with a number????
function alphanumeric($alphanumeric_field)
{
if(!preg_match("/[^a-zA-Z0-9]+$/",$alphanumeric_field))
return TRUE;
else
return FALSE;
}
any ideas much appreciated. As i am so frustrated with the preg_match
function!!
I haven't tested this, but you probably want something along these lines:
/^[A-Za-z][A-Za-z0-9]*$/
A '^' (carat) inside of '[]' means NOT (so, '[^A-Z]' means any single
character EXCEPT an upper-case letter). A '^' outside of '[]' means start of
line.
The above pattern, then, is looking for...
Start of line THEN a single alphabetic character (upper- or lower-case) THEN
zero or more alphabetic characters (upper- or lower-case) or decimal digits
THEN end of line (the '$' means end of line).
That's it really.
A.