Availability: |
| ||||||||
Property/method value type: | Boolean primitive | ||||||||
JavaScript syntax: | - | myRegExp.test(aString) | |||||||
Argument list: | aString | The string to be examined by the regular expression. |
This is not quite like the exec() method. In this case, you cannot establish whether the match occurs more than once or where in the string the match occurs.
This method simply returns true or false to indicate whether the pattern matches anything in the search string.
<HTML> <HEAD> </HEAD> <BODY> <SCRIPT> document.write("1 " + testForYearNumber("1") + "<BR>"); document.write("12 " + testForYearNumber("12") + "<BR>"); document.write("123 " + testForYearNumber("123") + "<BR>"); document.write("1234 " + testForYearNumber("1234") + "<BR>"); document.write("12345 " + testForYearNumber("12345") + "<BR>"); function testForYearNumber(aString) { var myRegExp = /^\d{4}$/; return myRegExp.test(aString); } </SCRIPT> </BODY> </HTML>
Prev | Home | Next |
RegExp.source | Up | RegExp.toSource() |
JavaScript Programmer's Reference, Cliff Wootton Wrox Press (www.wrox.com) Join the Wrox JavaScript forum at p2p.wrox.com Please report problems to support@wrox.com © 2001 Wrox Press. All Rights Reserved. Terms and conditions. |