简体   繁体   中英

Phone number validation using regex in java

I am new to Java and Regex.

I have to do simple phone number validations.

<input type="tel" maxlength="10">

Here user can't entered more than 10 characters. but i need, if user try to enter string values should not allow. Only numbers should allow.and no space in between numbers also should not allow. Please help me how can achieve with reqex.

You may use

<input onkeypress="return (event.charCode == 8 || event.charCode == 0) ? null : event.charCode >= 48 && event.charCode <= 57" type="number" maxlength="10" />
  • onkeypress="return (event.charCode == 8 || event.charCode == 0) ? null : event.charCode >= 48 && event.charCode <= 57" will handle numeric input
  • maxlength="10" - will set the max symbol length.

尝试这个

<input type="number" onKeyDown="if(this.value.length==10) return false;" />
 <input type="number" maxlength="10">

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM