Search code examples
htmlformsvalidationtel

Form Validation phone number pattern html5


I've searched far and wide but cannot seem to find the answer I need.

As we all know phone numbers around the world vary, my client's online form needs people to enter their phone number, but in a format of having the + symbol in the front. I know I can create a specific pattern to do this, but how do I create a pattern that has the + symbol at the front with a variable quantity of number after the symbol?

I'm happy to return a number like +60 1234567891.

I've also seen forms whereby the country code is selectable as part of the element... that would be good, but as long as I can solve my orginal issue I'll be happy.

Thanks


Solution

  • please look at the below script that can help you to validate phone number in html5 14 is the number of elements that can you enter by keyboard it accepts +sign with space and number.

    <input id="phonenum" type="tel" pattern="[+ 0-9]{14}" required >