[英]Regex for empty string or white space
I am trying to detect if a user enter whitespace in a textbox:我正在尝试检测用户是否在文本框中输入空格:
var regex = "^\s+$" ;
if($("#siren").val().match(regex)) {
echo($("#siren").val());
error+=1;
$("#siren").addClass("error");
$(".div-error").append("- Champ Siren/Siret ne doit pas etre vide<br/>");
}
if($("#siren").val().match(regex))
is supposed to match whitespace string, however, it doesn' t seems to work, what am I doing wrong ? if($("#siren").val().match(regex))
应该匹配空格字符串,但是,它似乎不起作用,我在做什么错?
Thanks for your helps谢谢你的帮助
I am trying to detect if a user enter whitespace in a textbox:我正在尝试检测用户是否在文本框中输入空格:
var regex = "^\s+$" ;
if($("#siren").val().match(regex)) {
echo($("#siren").val());
error+=1;
$("#siren").addClass("error");
$(".div-error").append("- Champ Siren/Siret ne doit pas etre vide<br/>");
}
if($("#siren").val().match(regex))
is supposed to match whitespace string, however, it doesn' t seems to work, what am I doing wrong ? if($("#siren").val().match(regex))
应该匹配空格字符串,但是,它似乎不起作用,我在做什么错?
Thanks for your helps谢谢你的帮助
I am trying to detect if a user enter whitespace in a textbox:我正在尝试检测用户是否在文本框中输入空格:
var regex = "^\s+$" ;
if($("#siren").val().match(regex)) {
echo($("#siren").val());
error+=1;
$("#siren").addClass("error");
$(".div-error").append("- Champ Siren/Siret ne doit pas etre vide<br/>");
}
if($("#siren").val().match(regex))
is supposed to match whitespace string, however, it doesn' t seems to work, what am I doing wrong ? if($("#siren").val().match(regex))
应该匹配空格字符串,但是,它似乎不起作用,我在做什么错?
Thanks for your helps谢谢你的帮助
I am trying to detect if a user enter whitespace in a textbox:我正在尝试检测用户是否在文本框中输入空格:
var regex = "^\s+$" ;
if($("#siren").val().match(regex)) {
echo($("#siren").val());
error+=1;
$("#siren").addClass("error");
$(".div-error").append("- Champ Siren/Siret ne doit pas etre vide<br/>");
}
if($("#siren").val().match(regex))
is supposed to match whitespace string, however, it doesn' t seems to work, what am I doing wrong ? if($("#siren").val().match(regex))
应该匹配空格字符串,但是,它似乎不起作用,我在做什么错?
Thanks for your helps谢谢你的帮助
I am trying to detect if a user enter whitespace in a textbox:我正在尝试检测用户是否在文本框中输入空格:
var regex = "^\s+$" ;
if($("#siren").val().match(regex)) {
echo($("#siren").val());
error+=1;
$("#siren").addClass("error");
$(".div-error").append("- Champ Siren/Siret ne doit pas etre vide<br/>");
}
if($("#siren").val().match(regex))
is supposed to match whitespace string, however, it doesn' t seems to work, what am I doing wrong ? if($("#siren").val().match(regex))
应该匹配空格字符串,但是,它似乎不起作用,我在做什么错?
Thanks for your helps谢谢你的帮助
I am trying to detect if a user enter whitespace in a textbox:我正在尝试检测用户是否在文本框中输入空格:
var regex = "^\s+$" ;
if($("#siren").val().match(regex)) {
echo($("#siren").val());
error+=1;
$("#siren").addClass("error");
$(".div-error").append("- Champ Siren/Siret ne doit pas etre vide<br/>");
}
if($("#siren").val().match(regex))
is supposed to match whitespace string, however, it doesn' t seems to work, what am I doing wrong ? if($("#siren").val().match(regex))
应该匹配空格字符串,但是,它似乎不起作用,我在做什么错?
Thanks for your helps谢谢你的帮助
I am trying to detect if a user enter whitespace in a textbox:我正在尝试检测用户是否在文本框中输入空格:
var regex = "^\s+$" ;
if($("#siren").val().match(regex)) {
echo($("#siren").val());
error+=1;
$("#siren").addClass("error");
$(".div-error").append("- Champ Siren/Siret ne doit pas etre vide<br/>");
}
if($("#siren").val().match(regex))
is supposed to match whitespace string, however, it doesn' t seems to work, what am I doing wrong ? if($("#siren").val().match(regex))
应该匹配空格字符串,但是,它似乎不起作用,我在做什么错?
Thanks for your helps谢谢你的帮助
One important note when talking about scripting and whitespaces: Browsers parsing spaces, whitespaces, tabs and linebreaks to spaces does mean that they actually ARE a whitespace. 在谈论脚本和空格时,一个重要的注意事项:浏览器将空格,空格,制表符和换行符解析为空格确实意味着它们实际上是一个空格。 Whitespaces themself are
\\xA0
(Char 160). 空白自己是
\\xA0
(Char 160)。 Ie often if you write PHP files on a mac and magically don't only hit space, you have a char that looks like a space but aint one. 也就是说,如果你在mac上编写PHP文件并且神奇地不仅仅是命中空间,那么你有一个看起来像空格而不是空格的字符。 To remove that and make the magical Error 500 that suddenly starts to come up disappear, remove all
\\xA0
(Char 160)'s from your script. 要删除它并使突然开始出现的神奇错误500消失,请从脚本中删除所有
\\xA0
(Char 160)。 (When searching, in TextWrangler / BBEdit you'd hit the checkbox "Grep" in the search dialog - should be similar in Coda, Eclipse etc). (当搜索时,在TextWrangler / BBEdit中你点击了搜索对话框中的“Grep”复选框 - 在Coda,Eclipse等中应该类似)。 It takes some time to figure out.
弄清楚需要一些时间。 Even if it does not 100% match the topic, it's the first result on google when you search for exactly that problem.
即使它不是100%匹配主题,它是谷歌搜索确切的问题时的第一个结果。 Hope it helps someone.
希望它可以帮助某人。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.