CodeWeblog.com » quot quot,prototype,javascript regular expressions » Commonly used in JavaScript regular expressions to verify

Commonly used in JavaScript regular expressions to verify


The correct format: "01" "09" and "1" "31."

Chinese characters matching the regular expression: [u4e00-u9fa5]
Matching double-byte characters (including Chinese characters included): [^ x00-xff]
Blank lines matching the regular expression: n [s |] * r
HTML tags matching the regular expression: / <(.*)>.*|< (.*) /> /
Both spaces matching the regular expression: (^ s *) | (s * $)
Email addresses match the regular expression: w +([-+.] w +) * @ w +([-.] w +) *. w +([-.] w +) *
Website URL matching the regular expression: http:// ([w-]+.)+[ w-]+(/[ w-./?%&=]*)?

(1) Applications: Calculation of the length of string (a double-byte character length of 2, ASCII character 1)
String.prototype.len = function () (return this.replace ([^ x00-xff] / g, "aa"). Length;)

(2) Application: javascript is not as trim as vbscript function, we can use this expression to achieve
String.prototype.trim = function ()
(
return this.replace (/ (^ s *) | (s * $) / g, "");
)
(3) Application: the use of regular expression IP addresses decomposition and conversion
function IP2V (ip) / / IP address into a corresponding numerical
(
re = / (d +). (d +). (d +). (d +) / g / / match the IP address regular expression
if (re.test (ip))
(
return RegExp. $ 1 * Math.pow (255,3)) + RegExp. $ 2 * Math.pow (255,2)) + RegExp. $ 3 * 255 + RegExp. $ 4 * 1
)
else
(
throw new Error ( "Not a valid IP address!")
)
)
(4) Applications: to extract from the URL address of the file name of the javascript program
s = "http://www.9499.net/page1.htm";
s = s.replace (/(.*/){ 0 ,}([^.]+).*/ ig, "$ 2"); / / Page1.htm
(5) Applications: restrictions on the use of regular expressions in the web form input text box
Use regular expressions to limit it only to input Chinese characters: onkeyup = "value =" / blog / value.replace (/["^ u4E00-u9FA5] / g, ")" onbeforepaste = "clipboardData.setData ( 'text', clipboardData . getData ( 'text'). replace (/ [^ u4E00-u9FA5] / g ,"))"
Restrictions on use of regular expressions can only enter the full-width characters are: onkeyup = "value =" / blog / value.replace (/["^ uFF00-uFFFF] / g, ")" onbeforepaste = "clipboardData.setData ( 'text', clipboardData.getData ( 'text'). replace (/ [^ uFF00-uFFFF] / g ,"))"
Restrictions on use of regular expressions can only enter a number: onkeyup = "value =" / blog / value.replace (/["^ d] / g, ")" onbeforepaste = "clipboardData.setData ( 'text', clipboardData.getData ( 'text'). replace (/ [^ d] / g ,"))"
Restrictions on use of regular expressions can only enter numbers and English: onkeyup = "value =" / blog / value.replace (/ [W] / g, "") "onbeforepaste =" clipboardData.setData ( 'text', clipboardData. getData ( 'text'). replace (/ [^ d] / g, "
Digg Technorati StumbleUpon Mixx del.icio.us Reddit BlinkList Furl YahooMyWeb feedburner

Tags: quot quot (RSS), prototype (RSS), javascript regular expressions (RSS), regular expression (RSS), url address (RSS), input chinese characters (RSS), decomposition (RSS), double byte characters (RSS), double byte character (RSS), pow (RSS), input text (RSS), conversion function (RSS), len function (RSS), valid ip address (RSS), ascii character (RSS), javascript program (RSS), character length (RSS), application javascript (RSS), blank lines (RSS), ig (RSS)

Permalink: http://www.codeweblog.com/commonly-used-in-javascript-regular-expressions-to-verify/

1 comments to “Commonly used in JavaScript regular expressions to verify”

  1. hotel in der T on 2010-01-25 10:37:48 :
    Design Prepare,trial insist desk though flight package anyone climb flat strong trend significance limited central full sign balance hospital though fruit market among promise defence previous aware business tiny north south beat ministry sun lie driver worth step floor deep moment plate lay little growth hope after spend probably marry individual affair neighbour item god letter nor most tool increase careful link first reject actual consequence ago terrible ask lot affair funny cat policy whereas fall unless door citizen essential data out prospect statement spirit content find institution late

Leave a reply