Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/295.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Textarea正则表达式_Php_Jquery_Regex - Fatal编程技术网

Php Textarea正则表达式

Php Textarea正则表达式,php,jquery,regex,Php,Jquery,Regex,我需要测试一个textarea以接受以下内容 新行\n,空格\s,a-zA-Z,0-9$@#()'!,+-/=_:.&欧元*和% 已编辑:到目前为止已尝试: var regx = a-zA-Z0-9?$@#()'!,+\-=_:.&€£*%\s ; /*don't know the method for checking regular expression So, some method like validate_regex to check/match */ regx.va

我需要测试一个textarea以接受以下内容

新行
\n
,空格
\s
a-zA-Z,0-9$@#()'!,+-/=_:.&欧元*
%

已编辑:到目前为止已尝试:

var regx = a-zA-Z0-9?$@#()'!,+\-=_:.&€£*%\s ;

/*don't know the method for checking regular expression
  So, some method like validate_regex to check/match
*/

regx.validate_regex(my_textbox_value);

请回答如何使用php和jquery为此编写正则表达式

假设
textbox id
是您的
textarea

var textboxValue = $("#textbox-id").val();
var regx = /^[a-zA-Z0-9?$@#()'!,+\-=_:.&€£*%\s]+$/;

if (regx.test(textboxValue))
    alert("correct"); // alerts
else
    alert('Incorrect!');​
试试这个:

HTML:


编辑:这是更新后的

似乎你只想要这个,别忘了投票并接受:)这里有点问题
+-=
。这定义了一个范围。因此,您要么转义连字符
+\-=
,要么将其放在字符类的末尾。您尝试过演示吗?
,+-=
将比您想象的更匹配。其中声明了一个范围。请看一下,
+-=
将从
+
匹配到
=
,这意味着它将匹配一些数字和其他字符,包括
我可以获得向上投票吗?:)
<textarea  id="foo"> </textarea>

<input type="text" id="bar"/>
var regx = /^[a-zA-Z0-9?$@#()'!,+\-=_:.&€£*%\s]+$/;

$('#foo').keyup(function() {
    if (regx.test(this.value)) $('#bar').val('correct');
    else  $('#bar').val('incorrect');
});