# js regular expression pure numbers how to represent the

### Regular expressions for php and js to validate plain numeric strings from 6 to 16 digits, please!

js’s:

vara=”123″;

vartr=/^[\d]{6,16}\$/;

php’s:

< p>\$str=”65″;

if(preg_match(“/^[\d]{6,16}\$/”,\$str)){echo “yes”;}else{echo “no”;}

### How can I tell in javascript that the input in input is a plain number?

Use regular expressions. If by pure numbers you mean integers (without the decimal point), you can do this:

functioncheck(){

varvalue=document.getElementById(“inputId”).value;

varreg=/^[1-9]\\ d*\$|^0\$/;//Note: intentionally limited to 0321 this format, if not needed, direct reg=/^\d+\$/;

if(reg.test(value)==true){

returntrue;

}else{

returnfalse;

}

}

If decimals also count as pure numbers, modify the reg regular expression to:

varreg=/^\d+(\. \d+)? \$/;

### Use js regular expression to detect phone number, requirement, must start with 1, can only be numbers, and is 11 digits, here regular expression how to write

The regular expression for cell phone number is “^1(3|4|5|7|8)\d{9}\$”, explanation is as follows

“^1” means start with 1, “(3|4|5|7|8)” means the second digit may be any one of 3/4/5/7/8, etc., in addition to the back of the \d means the 9 digits of the number [0-9], a total of 11 digits add up to the end.

The code is as follows:

functioncheckPhone(){

varphone=document.getElementById(‘phone’).value;

if(! (/^1(3|4|5|7|8)\d{9}\$/.test(phone))){

returnfalse;

}

}

The following are the commonly used elemental characters of js regular expressions:

Extended information:

Regular expressions, also known as rule expressions. (English: RegularExpression, often abbreviated as regex, regexp, or RE in code), a concept in computer science. Regular expressions are often used to retrieve and replace text that matches a certain pattern (rule).

### How to write js with regular expression validation that only allows input of numbers, or two decimal places after a number?

Only type or paste pure numbers:

<inputonkeyup=”value=value.replace(/[^\d]/g,”) “onbeforepaste=”clipboardData.setData(‘text’, clipboardData.getData(‘text’).replace(/[^\d]/g,”))”>

Page input box js regular validation of input value as a number, and only two decimal places are retained:

<input type=”text” id=”aaa”

obj.value=obj.value.replace(/[^\d.]/g,””);

//Guarantee that only one occurs. Not multiple.

obj.value=obj.value.replace(/\. {2,}/g,”.”) ;

// Must ensure that the first is a number and not .

obj.value=obj.value.replace(/^\. /g,””);

obj.value=obj.value.replace(“.” ,”\$#\$”).replace(/\. /g,””).replace(“\$#\$”,”.”) ;

// Only two decimals can be entered

obj.value=obj.value.replace(/^(\-)*(\d+)\. (\d\d). *\$/,’\$1\$2.3′);

}