Sergey Scopin Sergey Scopin - 5 months ago 49
jQuery Question

Jquery search doesn't find a symbols

I have an text input and input button. I want to prevent input from numbers.

<input type="text" name="lastNameSend" id="lastNameSend" placeholder="Surname" class="sendFormInput"></input>
<input id="sendPhysButton" class="button button_at_left" type="submit">

I use jquery regexp for it:

$(document).on("click","#sendPhysButton", function(event)
if ($("#lastNameSend").val().search("/[0-9]*/i"))

For some reason it always alerts -1. When I enter numbers it is -1, when I enter letters it is -1.
Here is a fiddle:
What's wrong?

Answer Source

There's a lot going on here that gets in the way, but the two big ones are quoting the regex, and using '*'. Try this: alert($("#lastNameSend").val().search(/\d/)); I also updated your fiddle

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download