Originally very simple small function, because the details toss for a while, so must be careful to do
The implementation of the code is also relatively simple you can refer to the
Core code:
function Renumdou (str) {
var regexp =/[^\d,,]]*/g;
Newstr=str.replace (RegExp, "");
Return NEWSTR
}
Cloud Habitat Community Small series to share another good code:
Automatically detect numeric replacement number regular expressions
<! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 transitional//en" > <HTML> <HEAD> <TITLE> New Document ;/title> <meta name= "generator" content= "EditPlus" > <meta name= "Author" content= "" > <meta NAME= "Keyw Ords "Content=" "> <meta name=" Description "content=" "> </HEAD> <BODY> <input onkeyup= ' Check (th
is) '/> </BODY> <script> function Check (obj) {var sreg =/^-+.*/g;
var zero =/^0[1-9]+\.*\d*/g;
var val = obj.value;
var plus = ';
if (Sreg.test (val)) {val = Val.replace (/-+/g, ');
plus = '-';
} val = Val.replace (/\s+/g, ');
if (/^\.+.*$/.test (val)) {val = '; } val = Val.replace (/[^\d\.]
/,''); val = val.replace (/(^\d+\.{
1}) (\d*). */g, ' $1$2 ');
val = val.replace (/(^\d+\.\d{3}) \d*/g, ' $ ');
val = Val.replace (/^[0]* (0{1}) ([1-9]*) (. *)/g, ' $1$2$3 ');
if (Zero.test (val)) {val = Val.replace (/0 ([1-9]+) (. *) $/, ' $1$2 ');
} obj.value = Plus+val;
} </script> </HTML>
REGEXP Use instructions
One: How regular expressions are created
1. Text format, using the following methods:
/pattern/flags (ie:/mode/tag)
2.RegExp constructor, using the following method:
New RegExp ("pattern" [, "Flags"]) (that is, new RegExp ("mode" [, "tag"])
Parameters:
Pattern (mode): Text that represents a regular expression
Flags: If this is specified, flags can be one of the following:
G:global match (full set matching)
I:ignore case (ignoring capitalization)
Gi:both Global Match and ignore case (matches all possible values, also ignores capitalization)
Note: The parameters in the text format do not use quotation marks, and the parameters of the two-factor-builder function are marked with quotation marks. So the following expression
is equivalent to:
/ab+c/i ==================== New RegExp ("Ab+c", "I")
Describe:
When you use constructor functions to create regular expressions, it is necessary to use normal string avoidance rules (which include leading characters in the string).
For example, the following two statements are equivalent:
re=new RegExp ("\\w+");
re=/\w+/
Note: The $ attribute is regexp preset
$, ..., $ property
A matching substring enclosed in parentheses, if any.
Is the property of the RegExp
Static, read-only
In JavaScript 1.2, NES version 3.0 offers
Description: Because input is a static property, it is not a property of an individual regular expression object. You can use Regexp.input to access the
Property.
The number of substrings that can be prefixed with parentheses is unrestricted, but the regular expression object can only retain the last 9 bars. If you want to visit all the
Parentheses inside the matching string, you can use the returned array.
<! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 transitional//en" >
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<script language= "JavaScript1.2" >
var regexp = new RegExp ("(\\w+) \\s (\\w+)" );
str = "John Smith";
Newstr=str.replace (RegExp, "$");
Newstr2=str.replace (RegExp, "$");
document.write ("Original string:" +str+ "<br/>");
document.write (newstr+ "<br/>");
document.write (newstr2+ "<br/>");
document.write (' $1= ' +regexp.$1+ " $2=" +regexp.$2);
</SCRIPT>
</HEAD>
<BODY>
</BODY>
Two: the match () method retrieves the specified value within the string, or finds a match for one or more regular expressions. It returns the specified value, not the position of the string.
Grammar
Stringobject.match (Searchvalue)
Stringobject.match (regexp) parameter description
Searchvalue required. Specify the string value to retrieve.
RegExp required. The RegExp object that prescribes the pattern to match. If the parameter is not a RegExp object, you need to pass it to the RegExp constructor first and convert it to a RegExp object.
return value
An array that holds the matching results. The contents of the array depend on whether RegExp has global flag G.
Description
The match () method retrieves the string stringobject to find one or more text that matches the regexp. The behavior of this method depends to a great extent on whether the regexp has a sign G.
If RegExp does not have a flag G, then the match () method can only perform a match in Stringobject. If no matching text is found, match () returns NULL. Otherwise, it returns an array that holds information about the matching text it finds.
Match Use Example:
<! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 transitional//en" > <HTML> <HEAD> <TITLE> New documen
T </TITLE> <script language= "JavaScript1.2" > var str= "1 plus 2 equal 3";
var str2= "11/23/55";
var results=str.match (New RegExp ("\\d+", "GI"));
for (Var i=0;i<results.length;i++) {document.write (results[i]+ "<br/>"); } var Res=str2.match (new RegExp (\\d\\d?) /(\\d\\d?)
/(\\d\\d)));
if (str2.length = = res[0].length) {document.write (res[1]+ "<br/>");
document.write (res[2]+ "<br/>");
document.write (res[3]+ "<br/>"); } </SCRIPT> </HEAD> <BODY> </BODY> </HTML> function Datecheck (value) {RE = new RegExp (\\d\\d?) /(\\d\\d?)
/(\\d\\d) ");
var result = Value.match (re); if (result) {if (result[0].length!= value.length) {alert ("Wrong date format.")
The correct format should be mm/dd/yy. ")
return false; }else{vart = result[3];
var y = parseint ("+" + t);
var m = parseint (result[1], 10)-1;
var day = parseint (result[2], 10);
var d = new Date (Y, M, day);
if (D.getfullyear ()!= y | | d.getmonth ()!= m | | d.getdate ()!= day) {alert ("Error date!")
return false; }else{var sm = Result[1].length = = 1? '
0 ' + result[1]:result[1]; var Sday = Result[2].length = = 1? '
0 ' + result[2]: result[2];
var sy = result[3];
else return SM + '/' + sday + '/' + sy; }}else{alert ("Wrong date format.
The correct format should be mm/dd/yy. ");
return false; }
}