Link to home
Start Free TrialLog in
Avatar of peps03
peps03

asked on

Only allow numbers, dashes (-) and comma's (,) in text field

Hi,

I would like to only allow numbers, dashes (-) and comma's (,) to be entered into a text field.

How should i do this? Without the use of jQuery please.

Thanks!
Avatar of Big Monty
Big Monty
Flag of United States of America image

try this:

var someName = document.getElementById("sometextField");
if(/^[-,a-z0-9-]+$/i.test(someName.value))
{
    alert('Name can only be alpha numeric with hypen or comma.');
    return;
}
ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of peps03
peps03

ASKER

Thanks!!!