Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Regular expression in Javascript

Status
Not open for further replies.

tshad

Programmer
Jul 15, 2004
386
US
I am trying to test for a comma delimited set of numeric values

This is supposed to work, but it doesn't seem to.

It allows "11,aa", as well as "12,aa,23".

if ($(this).val() != "") {
debugger;
var intRegex = /^[0-9]+(,[0-9]+)*,?/;
if (!intRegex.test(value)) {
alert("Field must be comma delimited numeric value.");
setFocus($(this));
}
}

Am I missing something in how javascript handles regular expressions?

Thanks,

Tom
 
You're not specifying end-of-input, so as long as it starts with a digit it can be followed by anything.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top