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, "
  • del.icio.us
  • StumbleUpon
  • Digg
  • TwitThis
  • Mixx
  • Technorati
  • Facebook
  • NewsVine
  • Reddit
  • Google
  • LinkedIn
  • YahooMyWeb

Related Posts of Commonly used in JavaScript regular expressions to verify

  • javascript regular expressions Basic Usage

    \ s: used to match a single address space, including the tab key and line breaks; \ S: In addition to a single space for the match at all outside of characters; \ d: for the match from 0-9 figures; \ w: to match letters, numbers or underscore charact ...

  • JS after ajax request return of the problem can not be implemented

    1: Send ajax request, in the onComplete, if back when the html contains a javascript, then these javascrip and will not be realized, it does not mean not to implement. This problem has troubled me for a long time, behind the hair and then put this kn ...

  • Javascript Object Model

    Javascript Object Model

  • JS in the Date type conversion

    http://blog.csdn.net/yzy0612/archive/2007/08/07/1730732.aspx

  • Detailed JS regular expressions

    Opening, or have to talk about ^ and $ that they are separately used to match the beginning and end of the string, the following examples to illustrate separately "^ The": there must be at the beginning of "The" string; "of d ...

  • JavaScript inheritance

    About JavaScript inherited a small example ... <! DOCTYPE HTML PUBLIC "- / / W3C / / DTD HTML 4.01 / / EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <meta http-equiv="Content-Type" conte ...

  • JavaScript String Functions Guinness

    Own JS function 1.Asc (x), Chr (x): convert characters, character code 2. Filter: Search string array of a specific string Format: v = filter (x, s [, include [, compare]]) Examples: Dim x ()={" kjwang "," wangkj "," peter &q ...

  • EJB ant script to deploy template works

    <? xml version = "1.0" encoding = "UTF-8"?> <! - Name Project name basedir build.xml file directory -> <project name="HelloWorld" basedir="."> <! - Property variables -> <! - The sour ...

  • java read file

    java read documents in two ways: java.io and java.lang.ClassLoader When using the java.io, when java.lang.ClassLoader use it? (Note: If prior to read xml file java read file clearly aware of these two methods have been like! Can take much less to und ...

Leave a Reply

Recent
Recent Entries
Tag Cloud
Random Entries