jquery: validate that text field is numeric
Posted
by George Johnston
on Stack Overflow
See other posts from Stack Overflow
or by George Johnston
Published on 2010-03-09T00:39:52Z
Indexed on
2010/03/09
0:51 UTC
Read the original article
Hit count: 1465
jQuery
|form-validation
I have simple issue -- I would like to check a field to see if it's numeric if it is not blank. I'm not using any additional plugins, just jQuery. My code is as follows:
if($('#Field').val() != "")
{
if($('#Field').val().match('^(0|[1-9][0-9]*)$'))
{
errors+= "Field must be numeric.<br/>";
success = false;
}
}
...It doesn't seem to work. Where am I going wrong?
Thanks, George
© Stack Overflow or respective owner