Common JS Regular expressions and filtering white-space characters

Source: Internet
Author: User
Tags control characters

The syntax of regular expressions is convenient for program processing, but is not actually a regular expression that can be used directly for filtering. Common regular expression pattern for filtering white-space characters

function Isnumber (handle) {
var pattern =/^ (d) {1,16}$/;
if (!pattern.exec (Handle.value)) {
Handle.value= '
Return "must enter a number!";}
return true;
}

Determine if it is a user account
function Isuserid (handle) {
var pattern =/^ (d|w) {3,14}$/;
if (!pattern.exec (handle.value)) return "must enter the number <br> and the length should be greater than or equal to 3 bits less than or equal to 14 bits!";
return true;
}

To determine whether the user name can be a letter or Chinese
function Isusername (handle) {
var pattern =/^[a-za-zu4e00-u9fa5]{2,50}$/;
if (!pattern.exec (handle.value)) return "must be Chinese letter or number <br> and the length should be greater than or equal to 2 bits or less or 50 bits!"
return true;
}

Determine whether it is a name: can be alphanumeric Chinese-_
function Isname (handle) {
var pattern =/^[a-za-z0-9-_u4e00-u9fa5]{1,30}$/;
if (!pattern.exec (handle.value)) return "must be Chinese letter or number!";
return true;
}


Determine if the menu name: can be alphanumeric Chinese-_
function Ismenuname (handle) {
var pattern =/^[a-za-z0-9-_u4e00-u9fa5]{2,200}$/;
if (!pattern.exec (Handle.value)) {return "must be a Chinese letter or number <br> and the length should be greater than or equal to 2 bits or less equal to 40 bits!";
Handle.value= '
}return true;
}

Here's how to use pattern to remove whitespace and space codes

var triminfo =
{basic://
Simple white-space character filtering in VB
, Classic:/s/
Traditional JS White-space character filtering
, Ecmascript5:/[sxa0u1680u180eu2000-u200au2028u2029u202fu205fu3000]/
Supplementary definition for/s in ECMAScript 5
, ex:/[sxa0u2028u2029]/
The impression is related to the identifier or string in JS, forget where it came from XD
, Control:/[x00-x1fx7f-x9f]/
A simple filter that adds control characters
, dotnet:/[sxa0u2000-u200bu3000ufeff]/
The default implementation of the. NET Platform
, Unicode:/[sx85xa0u1680u180eu2000-u200au2028u2029u202fu205fu3000]/
Filtering whitespace characters defined in the Unicode standard
, Complex:/[x00-x20x7f-xa0u1680u180eu2000-u200bu2028u2029u202fu205fu3000ufeff]/
Composite filtration, is the combination of the above several
};

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.