I have an HTML input box for phone numbers.
I use InputMask
to format the input 860000000
in the following 8 600 00 000
as input.
$(window).load(function()
{
var phones = [{ "mask": "# ### ## ###"}, { "mask": "# ### ## ###"}];
$('#phone').inputmask({
mask: phones,
greedy: false,
definitions: { '#': { validator: "[0-9]", cardinality: 1}} });
});
I also use the HTML template to check if the number starts with 86
, and only 9 digits, but with InputMask
it it stops working and cannot reach it in any way:
<label for="phone" class="first-col">Mobile No.:</label>
<input type="text" id="phone" placeholder="8 600 00 000" required pattern="(86)\d{7}" />
And CSS to add green borders, if valid:
input:required:valid {
box-shadow: 0 0 5px #5cd053;
border-color: #28921f;
}
Do you have any ideas?
Exists JS Fiddle
source
share