javascript - Extracting strings from an input field using regular expressions and jQuery -



javascript - Extracting strings from an input field using regular expressions and jQuery -

i trying match string in input field using regular look /[1-9][a-za-z]/ , insert <p> tag using jquery.

i modified this illustration jquery api docs include next if statement. when type '1a' in input field works, want exclude rest of string <p> includes matched string portion.

$("input").keyup(function () { if($(this).val().match(/[1-9][a-za-z]/)){ var value = $(this).val(); }; $("p").text(value); }).keyup();

did explain clearly? point me in right direction?

much appreciated,

so doing in above code if value of input field matches regular expression, assign value <p> tag. since, want assign matched string <p> tag, should do:

$("input").keyup(function () { var match = $(this).val().match(/[1-9][a-za-z]/); if(match){ var value = match[0]; // problem here }; $("p").text(value); }).keyup();

the match method of string returns array containing match if passed or undefined if match failed.

javascript jquery expression match

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

intellij idea - Update external libraries with intelij and java -

javascript - send data from a new window to previous window in php -