0

i want to validate user input for alphanumeric characters and for that im using

             var regex =  /^[a-zA-Z_0-9]$/;
             var asdfsfd = $('#vcr_LinkName').val();
             if (regex.test(asdfsfd)) {
                 alert("true");
             } else {
                 alert("false");                    
             }

but it always go into false condition what im doing wrong

1 Answer 1

5

Your expression would only match one single character.

Try this:

^[a-zA-Z_0-9]+$

Or

^\w+$

regards

Sign up to request clarification or add additional context in comments.

2 Comments

If i want to allow space as well what should i do?
Maybe there is a better solution, because this one allows tabs and linebreaks, too. But: ^(\w|\s)+$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.