krivaten
3/10/2014 - 8:40 PM

A set of useful regular expressions

A set of useful regular expressions

let regUrl = /^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/;
let regEmail = /^([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})$/;
let regAlphaNumeric = /^[a-z0-9_-]{6,18}$/;
let reqNumeric = /^\d+$/;
let regAlpha = /^[a-zA-Z ]*$/;

// to test a value
if(regUrl.test('foo')) {
	return true;
} else {
	return false;
}