I have small form in php with one input field for mobile number. currently i am entering mobile number in way that it start with 09 and maximum 11 digit . currently i can entered phone number of total 11 digit and if i wrote less than 11 than it successfully show error message. But i want mobile number should be entered in a way that there should b – after first four digit. and rest come after that. for example 0900-12345678 below is my code
<form action="action.php">
<label>Mobile No</label>
<input type="text" id="mobno" name="mobno" pattern="09[0-9]{9}" maxlength="11"><br><br>
<input type="submit" value="Submit">
</form>
2
Answers
I think change your pattern to this:
The pattern you’re using enforces a mobile number starting with "09" and followed by exactly 9 digits. However, this doesn’t match the format you want (e.g., 0300-12345678), and it doesn’t allow for the inclusion of a – after the first four digits
You need to use this pattern instead 03[0-9]{2}-[0-9]{8}
And you should increase the maxlenght to 13