开发者

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

开发者 https://www.devze.com 2023-02-01 15:22 出处:网络
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. 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

精彩评论

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

关注公众号