Home Web Front-end JS Tutorial js limit number js limit input implementation code_javascript skills

js limit number js limit input implementation code_javascript skills

May 16, 2016 pm 05:47 PM
number enter limit

1. Only Chinese characters can be input
Copy code The code is as follows:



2. Only numbers can be entered
Copy code The code is as follows:



Simple prohibition of inputting Chinese characters
Copy code The code is as follows:



Enter numbers and decimal points:
Copy code The code is as follows:

onkeyup="value=value.replace(/[^d{1,}.d{1,}|d{1,}]/g,'')"

javascript can only enter numbers and ":".2007-11-24 15:50
Only numbers and ":" can be used, for example, when entering time.
Copy code The code is as follows:



Only letters and equal signs can be entered, but Chinese characters cannot be entered.

Other things:
Script javascript that can only enter numbers- -
Copy code The code is as follows:



The first half of the sentence means that keyboard typing can only be numbers, and the second half of the sentence means that pasting can only be numbers
Copy code The code is as follows:




3. JavaScript limits only numbers and English to be entered
Copy code The code is as follows:

function isregname( checkobj)
{
var checkOK = "0123456789 -_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
var checkStr = checkobj;
var allValid = true;
var decPoints = 0;
for (i = 0; i < checkStr.length; i )
{
ch = checkStr.charAt(i);
for (j = 0; j < checkOK.length; j )
if (ch == checkOK.charAt(j))
break;
if (j == checkOK.length)
{
allValid = false;
break;
}
}
return (allValid)
}
----------------
if(!(isregname(obj.loginname.value))){
alert("[Member code] does not comply with the specification, member code It can only be English letters or numbers");
obj.loginname.focus();
return(false);
}
if(!(isregname(obj.password.value))) {
alert("[Password] does not meet the specifications, the password can only be English letters or numbers");
obj.password.focus();
return(false);
}

4.javascript can only input English and numbers into the input box
Copy code The code is as follows:



5. You can use Javascript to check the text box and filter out non-0-9 characters
Copy code The code is as follows:

[url=http://blog.csdn.net/xujh/admin/EditPosts.aspx] [/url]

6. Only the IP address format can be entered in the text box
Copy code The code is as follows:






<script> <br>function mask(obj ){ <br>obj.value=obj.value.replace(/[^d]/g,'') <br>key1=event.keyCode <br>if (key1==37 || key1==39) <br>{ obj.blur(); <br>nextip=parseInt(obj.name.substr(2,1)) <br>nextip=key1==37?nextip-1:nextip 1; <br>nextip= nextip>=5?1:nextip <br>nextip=nextip<=0?4:nextip <BR>eval("ip" nextip ".focus()") <BR>} <BR>if(obj.value. length>=3) <br>if(parseInt(obj.value)>=256 || parseInt(obj.value)<=0) <BR>{ <BR>alert(parseInt(obj.value) "IP Wrong address! ") <BR>obj.value="" <BR>obj.focus() <BR>return false; <BR>} <BR>else <BR>{ obj.blur(); <BR>nextip=parseInt( obj.name.substr(2,1)) 1 <BR>nextip=nextip>=5?1:nextip <br>nextip=nextip<=0?4:nextip <BR>eval("ip" nextip ".focus ()") <BR>} <BR>} <BR>function mask_c(obj) <BR>{ <BR>clipboardData.setData('text',clipboardData.getData('text').replace(/[^d ]/g,'')) <BR>} <BR></script>
IP address input

IP address input

.
.
.



Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Will R.E.P.O. Have Crossplay?
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Disabling Win11 Input Experience Guide Disabling Win11 Input Experience Guide Dec 27, 2023 am 11:07 AM

Recently, many Win11 users have encountered the problem that the input experience dialog box always flickers and cannot be turned off. This is actually caused by the default system services and components of Win11. We need to disable the relevant services first, and then disable the input experience service. Solved, let’s try it out together. How to turn off the input experience in win11: First step, right-click the start menu and open "Task Manager". Second step, find the three processes "CTF Loader", "MicrosoftIME" and "Service Host: Textinput Management Service" in order, right-click "End Task" "The third step, open the start menu, search and open "Services" at the top. The fourth step, find "Textinp" in it

Windows input encounters hang or high memory usage [Fix] Windows input encounters hang or high memory usage [Fix] Feb 19, 2024 pm 10:48 PM

The Windows input experience is a key system service responsible for processing user input from various human interface devices. It starts automatically at system startup and runs in the background. However, sometimes this service may automatically hang or occupy too much memory, resulting in reduced system performance. Therefore, it is crucial to monitor and manage this process in a timely manner to ensure system efficiency and stability. In this article, we will share how to fix issues where the Windows input experience hangs or causes high memory usage. The Windows Input Experience Service does not have a user interface, but it is closely related to handling basic system tasks and functions related to input devices. Its role is to help the Windows system understand every input entered by the user.

iOS 17: How to change iPhone clock style in standby mode iOS 17: How to change iPhone clock style in standby mode Sep 10, 2023 pm 09:21 PM

Standby is a lock screen mode that activates when the iPhone is plugged into the charger and oriented in horizontal (or landscape) orientation. It consists of three different screens, one of which is displayed full screen time. Read on to learn how to change the style of your clock. StandBy's third screen displays times and dates in various themes that you can swipe vertically. Some themes also display additional information, such as temperature or next alarm. If you hold down any clock, you can switch between different themes, including Digital, Analog, World, Solar, and Floating. Float displays the time in large bubble numbers in customizable colors, Solar has a more standard font with a sun flare design in different colors, and World displays the world by highlighting

How to remove comment restrictions on video accounts? What is the word limit for comments on a video account? How to remove comment restrictions on video accounts? What is the word limit for comments on a video account? Mar 22, 2024 pm 02:11 PM

With the popularity of video accounts on social media, more and more people are beginning to use video accounts to share their daily lives, insights and stories. However, some users may experience comments being restricted, which can leave them confused and dissatisfied. 1. How to remove comment restrictions on video accounts? To lift the restriction on commenting on a video account, you must first ensure that the account has been properly registered and real-name authentication has been completed. Video accounts have requirements for comments. Only accounts that have completed real-name authentication can lift comment restrictions. If there are any abnormalities in the account, these issues need to be resolved before comment restrictions can be lifted. 2. Comply with the community standards of the video account. Video accounts have certain standards for comment content. If the comment involves illegal content, you will be restricted from speaking. To lift comment restrictions, you need to abide by the community of the video account

C++ program to round a number to n decimal places C++ program to round a number to n decimal places Sep 12, 2023 pm 05:13 PM

Representing numbers as output is an interesting and important task when writing a program in any language. For integer types (data of type short, long, or medium), it is easy to represent numbers as output. For floating point numbers (float or double type), sometimes we need to round them to a specific number of decimal places. For example, if we want to represent 52.24568 as three decimal places, some preprocessing is required. In this article, we will introduce several techniques to represent floating point numbers to a specific number of decimal places by rounding. Among the different approaches, it is important to use a C-like format string, use the precision argument, and use the round() function from the math library. Let’s look at them one by one. with

How to use JavaScript to drag and zoom images while limiting them to the container? How to use JavaScript to drag and zoom images while limiting them to the container? Oct 20, 2023 pm 04:19 PM

How does JavaScript implement dragging and zooming of images while limiting them to the container? In web development, we often encounter the need to drag and zoom images. This article will introduce how to use JavaScript to implement dragging and zooming of images and limit operations within the container. 1. Drag the picture To drag the picture, we can use mouse events to track the mouse position and move the picture position accordingly. The following is a sample code: //Get the picture element varimage

Find numbers that are not divisible by any number in a range, using C++ Find numbers that are not divisible by any number in a range, using C++ Sep 13, 2023 pm 09:21 PM

In this article, we will discuss the problem of finding numbers between 1 and n (given) that are not divisible by any number between 2 and 10. Let us understand this with some examples - Input:num=14Output:3Explanation:Therearethreenumbers,1,11,and13,whicharenotdivisible.Input:num=21Output:5Explanation:Therearefivenumbers1,11,13,17,and19,whicharenotdivisible. Solved Simple method if

Solve win11 search bar input problem Solve win11 search bar input problem Dec 26, 2023 pm 12:07 PM

The search bar is a very useful function in the win11 system, which can help us find the settings, functions and services we want. However, some friends have encountered the situation where the win11 search bar cannot be entered. We can modify the relevant data in the registry to solve the problem. Let's follow the editor to solve it. What to do if you can’t type in the win11 search bar 1. First, we can press “win+r” on the keyboard to bring up run. 2. Then enter "regedit" and press Enter to open the Registry Editor. 3. Then enter "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Expl" in the path above

See all articles