Fastest method for testing a fixed phone number pattern

后端 未结 6 2000
孤街浪徒
孤街浪徒 2021-01-05 20:11

So, the challenge is that we are trying to detect if a string matches a fixed phone number pattern, this is a simple string pattern.

The pattern is:

         


        
6条回答
  •  庸人自扰
    2021-01-05 20:59

    you can use regex for that:

    if(/^[0-9]{3}-[0-9]{3}-[0-9]{4}$/.test('123-456-7890'))
        //ok
    else
        //not ok
    

提交回复
热议问题