Fokrule
Fokrule

Reputation: 854

html input type number is not taking 0.

My Html input type number is not accepting 0 as a first input. It only accept 1 to 9 digit as a first input. Here is my code

<input type="number" class="form-control" name="signup_phone" id="signup_phone" placeholder="<?php esc_html_e('Phone', 'service-finder'); ?>">

If i give input 120124214 it accept. But if I give 0124452 it is not taking my input.

Upvotes: 1

Views: 5253

Answers (4)

Shashwat Gupta
Shashwat Gupta

Reputation: 5272

Use this simple code

<input type="tel" pattern="[0-9]*">

Upvotes: 2

Bmd
Bmd

Reputation: 1317

This might be an issue with phone number validation. See this SO answer.

NANP numbers take the form NXX NXX XXXX where N is a digit 2-9 and X is a digit 0-9. Additionally, area codes and exchanges may not take the form N11 (end with two ones) to avoid confusion with special services except numbers in a non-geographic area code (800, 888, 877, 866, 855, 900) may have a N11 exchange.

Upvotes: 0

Naga Sai A
Naga Sai A

Reputation: 10975

To achieve expected result, use below option

<input type="text" onkeypress="return event.charCode === 0 || /\d/.test(String.fromCharCode(event.charCode));">

https://codepen.io/nagasai/pen/mxdjxY

Upvotes: -2

Christian Hur
Christian Hur

Reputation: 429

What browser are you using? Works fine for me. Test it here.

function validate(){
  alert(document.forms[0].signup_phone.value);
  }
<form onsubmit="return validate()">
<input type="number" class="form-control" name="signup_phone" id="signup_phone" placeholder="something">
<input type="submit">
</form>

Upvotes: 0

Related Questions