Regular expression with a non-white-space character and no more than n characters

Source: Internet
Author: User

Regular Expression Rule analysis:
. { 7}: The entire string length is greater than 6, note: here. Match any character
^s*$: The entire string is empty or is a white space character
The author uses the order of the regular expression to negate the look, indicates that there can be no more than 7 characters after the start (^), or that the entire string is empty (if S is not, ^$ represents empty), or all whitespace characters (s*).
However, the regular expression can remove the ^ from the look in the condition, that is, the/^ (?!. {7}|s*$)/g, because the rules were already in the beginning of a ^.

  code is as follows copy code

<script Type= "Text/javascript" >
/**
* has at least one non-white-space character and no more than 6-character regular expression
*

/
var pattern =/^ (?!. {7}|s*$)/g;
var str = "";
var str1 = "";
var str2 = "a";
var str3 = www.111cn.net;
var str4 = "a";
document.write (Pattern.test (str))
document.write (Pattern.test (str1))
document.write (Pattern.test ( STR2))
document.write (Pattern.test (STR3))
document.write (Pattern.test (STR4))
</script>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.