I have a textbox whereby the user needs to input his/her mobile number. However I need to validate the first 2 numbers (characters) to make sure that the mobile number is in the correct format (as one of the validation rules).
The mobile number needs to start with any of the following 2 digits:
44xxxxxx
55xxxxxx
65xxxxxx
78xxxxxx
Can anyone tell me how it’s possible to validate the first two characters number and check that they are either one of the options mentioned above?
EDIT
This is what I had tried but it did not work:
HTML
<input id="mob" name="mob" type="tel" placeholder="Enter your mobile number">
<a href="#" id="validate">Validate</a>
JS
var mobile_prefix = $('#mob').subsubstr(0,2);
$('#validate').click(function(){
if (mobile_prefix == 44||55||65||78) {
alert('correct');
}
else {
alert('incorrect');
}
});
I think .match() has what you’re looking for. Just brush up on some regular expressions.