Where are javascript's regular expressions (regex) used? [closed]
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
开发者_Go百科 Improve this questionAre they useful to know? How are they used?
Regular expressions are not a JavaScript-specific feature and are typically used to check for faults in use input, for example to notify users who forget the @ or domain part of an email address or too few/many digits in a phone number. For more examples, look over there.
- Email address validation
JavaScript is like Perl, has native regular expression notation. Regular expressions are used to match texts. For example, validating age:
if (field.value.match(/^\s*\d+\s*$/) === null) alert("error: invalid age.");
Read this for a documentation: https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/RegExp
and JS form validation tutorial: http://www.devarticles.com/c/a/JavaScript/Form-Validation-with-JavaScript-Regular-Expressions-Part-1/
精彩评论