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

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

WBOY
WBOYOriginal
2016-06-13 12:51:33755browse

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:
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