check first two number jquery

Solutions on MaxInterview for check first two number jquery by the best coders in the world

showing results for - "check first two number jquery"
Alizee
28 Nov 2019
1// Will work for " 123433 " or "12345634 ", etc.
2var value = $(this).val(),
3    re = /^\s*(\d{4})(\d+)\s*$/, // better to initialize only once somewhere in parent scope
4    matches = re.exec(value),
5    expectedCode = 3541,
6    expectedLength = 13;
7if(!!matches) {
8    var code = matches[1]; // first group is exactly first 4 digits
9    // in matches[2] you'll find the rest numbers.
10    if(value.length == expectedLength && code == expectedCode) {
11        // Change the color...
12    }
13}