Skip to content Skip to sidebar Skip to footer

Validating 10 Characters, Can Only Be Numbers, Then Redirecting To A Web Address

So what I need to have happen: User types in 10 digits (only digits) and clicks “Submit” On submit – the user gets redirected to another landing page. Here is what I’ve don

Solution 1:

You can check to see that a string is a 10-character string of digits like this:

if (/^\d{10}$/.test(someValue)) {
  // it is OK
}
else {
  // not OK
}

Solution 2:

replace your if with

if (isNaN(myField) || myField.length !== 10) {

EDIT: your best bet looks to be

if (/^\d{10}$/.test(someValue)) {

Which is Pointy's answer, so go with that :)

Post a Comment for "Validating 10 Characters, Can Only Be Numbers, Then Redirecting To A Web Address"