Regular Expression-evaluate php regular expressions, and some js regular expressions cannot be used.

Source: Internet
Author: User
A string can only contain Chinese and English characters, numbers, and php regular expressions of & #039;-& #039;, & #039; _ & #039. Use the preg_match () function. A string can only contain Chinese and English, numbers ,'-','_'Php regular expression. Use Preg_match ()Function.

Reply content:

A string can only containChinese and English, numbers ,'-','_'Php regular expression. UsePreg_match ()Function.

I think you mainly want to solve the problem of matching Chinese characters. Try this.

Preg_match ("/^ [\ x {4e00}-\ x {9fa5}] + $/u", $ str)

If an English number and two symbols are added

Preg_match ("/^ [\ x {4e00}-\ x {9fa5} a-zA-Z0-9 _ \-] + $/u", $ str)

Refer to php Regular Expression matching for Chinese characters. Let's take a look. The author has spent some time on this.

Related Article

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.