validating 10 characters, can only be numbers, then redirecting to a web address

后端 未结 2 743
醉梦人生
醉梦人生 2021-01-27 17:52

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 wh

相关标签:
2条回答
  • 2021-01-27 18:38

    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
    }
    
    0 讨论(0)
  • 2021-01-27 18:45

    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 :)

    0 讨论(0)
提交回复
热议问题