简体   繁体   中英

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 ?

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 ?

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 ?

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 ?

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 ?

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 ?

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 ?

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). 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. 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. (When searching, in TextWrangler / BBEdit you'd hit the checkbox "Grep" in the search dialog - should be similar in Coda, Eclipse etc). 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. Hope it helps someone.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM