开发者

Where are javascript's regular expressions (regex) used? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.

Want to improve this question? Add details and clarify the problem by editing this post.

Closed 8 years ago.

开发者_Go百科 Improve this question

Are 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/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜