Home Backend Development PHP Tutorial formvalidtor在thinkphp中的正则表达式书写的有关问题――大家帮忙

formvalidtor在thinkphp中的正则表达式书写的有关问题――大家帮忙

Jun 13, 2016 pm 12:51 PM
nbsp thinkphp

formvalidtor在thinkphp中的正则表达式书写的问题――大家帮忙

本帖最后由 wadelin511 于 2013-03-13 12:25:31 编辑
使用formValidator-4.1.3.js进行email格式check。
书写方式如下。

   $("#email").formValidator({onShow:"请输入邮箱",onFocus:"邮箱6-100个字符,输入正确了才能离开焦点",onCorrect:"恭喜你,你输对了",defaultValue:"@"}).inputValidator({min:6,max:100,onError:"你输入的邮箱长度非法,请确认"}).regexValidator({regExp:"^([\\w-.]+)@(([[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.)|(([\\w-]+.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(]?)$",onError:"你输入的邮箱格式不正确"});


在静态网页中测试正常。但是在thinkphp的模板文件中,经过解析后的代码变成了
regExp:"^([\w-.]+)@(([[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.)|(([\\w-]+.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(]?)$"

导致formValidator报字“符集越界”的问题。

为什么表达式被更改了。\\w变成了\w?
请大家帮忙确认!
thinkphp formvalidtor 符集越界
------解决方案--------------------
模板文件会被读取到变量中,所以 \\w 变成了 \w
要写作 \\\w 或 \\\\w
------解决方案--------------------
这就不清楚了,需要看 php 的 C 源代码才能分析原因
不过这不是什么人都可以做到的
实际使用中也不必深究,遇到加一个“\”不行时就再加一个,如此循环知道不出错

你可以看到国外的不少代码中会有连续四五个 \ 的
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Solution: Your organization requires you to change your PIN Solution: Your organization requires you to change your PIN Oct 04, 2023 pm 05:45 PM

Solution: Your organization requires you to change your PIN

How to adjust window border settings on Windows 11: Change color and size How to adjust window border settings on Windows 11: Change color and size Sep 22, 2023 am 11:37 AM

How to adjust window border settings on Windows 11: Change color and size

Display scaling guide on Windows 11 Display scaling guide on Windows 11 Sep 19, 2023 pm 06:45 PM

Display scaling guide on Windows 11

10 Ways to Adjust Brightness on Windows 11 10 Ways to Adjust Brightness on Windows 11 Dec 18, 2023 pm 02:21 PM

10 Ways to Adjust Brightness on Windows 11

How to turn off private browsing authentication for iPhone in Safari? How to turn off private browsing authentication for iPhone in Safari? Nov 29, 2023 pm 11:21 PM

How to turn off private browsing authentication for iPhone in Safari?

Win10/11 digital activation script MAS version 2.2 re-supports digital activation Win10/11 digital activation script MAS version 2.2 re-supports digital activation Oct 16, 2023 am 08:13 AM

Win10/11 digital activation script MAS version 2.2 re-supports digital activation

How to run thinkphp project How to run thinkphp project Apr 09, 2024 pm 05:33 PM

How to run thinkphp project

How to Hide and Unhide Folders on Windows 11 [3 Ways] How to Hide and Unhide Folders on Windows 11 [3 Ways] Sep 23, 2023 am 08:37 AM

How to Hide and Unhide Folders on Windows 11 [3 Ways]

See all articles