I have the following rules for phone number data entry:
- For USA phones, it must follow format (999) 999-9999
- For non-USA phones, it must start with a + followed by any combination of digits, hyphens, and spaces (basically, much less strict than the USA format)
I have regex validation that ensures that the entered phone number matches these rules. I want to use a phone format mask that follows the above rules.
For example, the simple case of just allowing the specific USA format, I can do:
<label for="phone">Enter Phone Number:</label>
<input type="text" id="phone" name="phone">
<script type="text/javascript">
$(function () {
$('.usa-phone').mask("(999) 999-9999");
});
</script>
This would display something like this in the textbox when the user clicks to focus the phone textbox:
(___) ___-____
But how do I then allow for international phones that start with "+" sign in the same input field?
For example +99 (99) 9999-9999
.