0

I am working on a search box to search users of my webapp. I want the user to enter the firstname and lastname of the user. I want to validate the user and make sure that user enters two string parts viz. firstname and lastname in the textbox. If not done so ...i want an error to be thrown. Please help with examples. I m new to javascript . My webapp is jsp/servlet based.

1
  • did you try something? Commented Mar 11, 2015 at 17:12

1 Answer 1

2

see this example in jsfiddle.

http://jsfiddle.net/YrFfG/

 $(document).ready(function() {
    $("#btn").click(function(e) {
    if (/\w+\s+\w+/.test($("#cname").val())) {
        alert("good");
    } else {
        alert("bad");
    }

    e.preventDefault();
  });
});
Sign up to request clarification or add additional context in comments.

Comments

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.