javascript - Regular expression with JQuery -


-hi i'm new jquery.

i have recognize [h] @ jquery.

at moment, recognize letters.

$(document).ready(function () {     $(":button#boton").click(function () {         if ($(":text#texto").attr("value").match(/^[a-za-z]+$/)) {             alert("bien");         } else {             alert("esto no son letras");         }     }); }); 

how can scape symbol [?. \?

thank in advance. kr. blanca

you can escape special characters in regex preceding \:

if ($(":text#texto").attr("value").match(/^[a-za-z\[h\]]+$/)) { //                                                ^^^^^ 

to recognize [h] using regex:

if ($(":text#texto").attr("value").match(/\[h\]+/g)) { //                                        ^^^^^  ^ 

a backslash precedes special character indicates next character not special , should interpreted literally. example, pattern /a*/ relies on special character '' match 0 or more a's. contrast, pattern /a*/ removes specialness of '' enable matches strings 'a*'.


Comments

Popular posts from this blog

How to connect android app to App engine -

gcc - MinGW's ld cannot perform PE operations on non PE output file -

php - display validation error message next to the textbox in codeigniter -