Ruslan Ulanov’s Codeshack

The developer’s notebook

Archive for the ‘regex’ tag

Useful JavaScript Regular Expression Functions

leave a comment

Here’s a few links for commonly used REGEXs..

10+ Useful JavaScript Regular Expression Functions to improve your web applications efficiency

[javascript]// check that an input string looks like a valid email address.

var isEmail_re = /^\s*[\w\-\+_]+(\.[\w\-\+_]+)*\@[\w\-\+_]+\.[\w\-\+_]+(\.[\w\-\+_]+)*\s*$/;
function isEmail (s) {
return String(s).search (isEmail_re) != -1;
}[/javascript]

 
 

[javascript]// returns a string with everything but the digits removed. Could be used to validate phone numbers, etc.

function getdigits (s) {
return s.replace (/[^\d]/g, “”);
}
[/javascript]

Written by Ruslan Ulanov

September 4th, 2009 at 12:16 pm

Posted in JavaScript

Tagged with ,