Archive for April 18, 2007

JavaScript Regular Expression Asterisk

Posted in JavaScript, Software, Web, programming on April 18, 2007 by Joey

The asterisk (*) special character is used in JavaScript regular expressions to match zero or more occurrences of the previous item.

var StringToTest = 'abc1';
var IsFound = /^\w{3}\d*$/.test(StringToTest);
alert(IsFound);

The preceding code will return true for any three-character string, followed by zero or more digits.

Related articles:
JavaScript Regular Expressions
JavaScript Regular Expression Special Characters: $ ^