Home > JavaScript > Regex cheat sheet

Regex cheat sheet

Javascript: var rxxx = /^.$/;  // start end anything allow  if( reg.test(‘abc123’) == true) { // do this…}

Email

remail = /^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/;

Name:

var rname = /^\d+|\d+[a-zA-Z]+$/; // disallow digit or alphabet + digit

Street:

var rstreet = /.+/; // greater then 1 input

Phone:

var rphone = /^[0-9]+$/; // allow number inputs

Website:

rwebsite = /^((http|https|ftp):\/\/)?([\w-]+\.)+([\w-.\/?%&=]*)?$/;

Advertisements
Categories: JavaScript
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: