JavaScript Validate jquery regex - number start with 931 validate jquery regex,jquery validate regex rule,jquery validate regex

I need to validate number that use inputs into input box. Number must be exactly 12 characters long and start with 931.

var reg = /^931[0-9]$/;
var val = $("#sms_number").val();

if (val.length === 12 && reg.test(val)) {                    


}

Above is incorrect.

Answer:1
var reg = /^931\d{9}$/;
var val = $("#sms_number").val();
if (reg.test(val)) {
    // ....
}
Answer:2

In a concise way the following should work:

/^931[0-9]{9}$/.test($("#sms_number").val())? console.log(true): console.log(false);

xdazz's answer is correct, but I'd suggest not to use \d if you are not trying to accommodate unicode numbers as well. If you are fine with only English numbers (I think that's the way it meant to be, as it uses 931 prefix which is indeed in English) you should use [0-9] instead of \d. Former is faster.

Answer:3

I use pywebkit and html5 to develope desktop map server. Map tiles store in sqlite database. So when I set html img's src, I have two options. One is read image from database and b64encode it, ...

I use pywebkit and html5 to develope desktop map server. Map tiles store in sqlite database. So when I set html img's src, I have two options. One is read image from database and b64encode it, ...

I'm working on a Backbone application and I'm not sure if the way what I'm trying to do is the correct way. I have an application view and inside that application view I'm trying to append a ...

I'm working on a Backbone application and I'm not sure if the way what I'm trying to do is the correct way. I have an application view and inside that application view I'm trying to append a ...

  1. backbone js nested views

I need to test all the words entered into an input against 3 objects and determine which array they belong to so I can output a URL to an API. I want to achieve this with Javascript/jQuery. For ...

I need to test all the words entered into an input against 3 objects and determine which array they belong to so I can output a URL to an API. I want to achieve this with Javascript/jQuery. For ...

I'm having a bit of trouble trying to loop out multiple markers onto a map using information stored in an array. The code creates the map no problem, but it's not displaying the markers I'm trying ...

I'm having a bit of trouble trying to loop out multiple markers onto a map using information stored in an array. The code creates the map no problem, but it's not displaying the markers I'm trying ...

  1. google maps creating a route
  2. google maps creating a map
  3. google maps creating custom markers
  4. google maps creating markers
  5. google maps creating custom map
  6. creating google maps with pins
  7. creating google maps api key
  8. creating google maps from postcode data
  9. creating google maps directions