Input box limit can only enter a number and specify the number length (use and enter the phone number)

Source: Internet
Author: User

Now more and more account names use mobile phone number to log in, in order to reduce the front and back of the interaction, users need to input the format of the judgment,

The current conventional approach is to make judgments after the input is completed.

The following method specifies that only numbers can be entered, and characters in other formats cannot be entered:

<inputonkeydown= "Onlynum ();"style= "ime-mode:disabled"maxlength= "One">//ime-mode:disabled: The function is to completely disable the IME. For a control that has focus (such as an input box), the user can not activate other property values of Ime;//ime-mode and function as follows://auto: Default value. Does not affect the state of the IME. Same as//active when no Ime-mode property is specified: Specifies all characters that are entered using the IME. The local language input method is activated. Users can still revoke the activation IME//inactive: Specifies all characters that do not use IME input. The non-native language is activated. The user can still revoke the activation Ime//maxlength: This property specifies the length of the input box, in which the content is entered;<Scriptlanguage=javascript>functionOnlynum () {if(!(Event.keycode== $)&&!(Event.keycode==8)&&!(Event.keycode==Panax Notoginseng)&&!(Event.keycode== the))    if(!((Event.keycode>= -&&Event.keycode<= $)||(Event.keycode>= the&&Event.keycode<= the)) Event.returnvalue=false; //block input when executing to the statement, can be analogous to block the bubbling principle or prohibit right-click function;}</Script>

This method still has some problems, can not prevent the third party input any characters, if there are other more perfect solution, please leave a message, I also learn to learn.

Input box limit can only enter a number and specify the number length (use and enter the phone number)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.