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!
JavaScript
Last Comment
peps03
8/22/2022 - Mon
Big Monty
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;
}
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
var someName = document.getElementById("s
if(/^[-,a-z0-9-]+$/i.test(
{
alert('Name can only be alpha numeric with hypen or comma.');
return;
}