3

I'm looking for a way to validate a single field at a time. This is so, while a user is filling in a form, each time the keypress or blur event occurs for each field, i can validate that field individually and show / hide its error message.

Is that possible? If so, how can I do it? Some google searching hasn't turned up any results which validate a single field, rather than the whole form.

1
  • @BheshGurung It is a web application but I'm using Google Web Toolkit, so validation is actually being done via hibernate validator.. Commented Feb 22, 2014 at 22:26

2 Answers 2

4

You can use javax.validation.Validator#validateProperty() for that purpose.

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

1 Comment

Sorry i came too late. I am using Hibernate and i tried using this to validate a String parameter value, but it didn't work either. Could you take a look to this question ? I would appreciate it. Regards!
-1

I'd recommend that you try using Javascript Regular Expressions to validate user inputs and show/hide error messages. I provided a code implementation example in the post at this link: Example using Regular Expresssions

Add an event listener to relevant input field in the DOM to provide responsiveness.

var letterField = document.getElementById('letterField'); // DOM element containing user input 
letterField.addEventListener('keyup', function() { // key press event listener using anonymous function
    if (event.keyCode === 13) { // run this code if the 'enter' key is pressed
        if ( ... ) { 
            ...
        };
    };
};

If you want to add effects, include the following code to transition the error message. Refer to the jQuery API for other effects:

userInputError.delay(800).fadeOut(); 

3 Comments

Thanks, but I'm using Google Web Toolkit which compiles java to javascript, so actually I'm looking for a way to do this via hibernate.. any ideas?
It seems I've bitten off more than I can chew in answering this post. All is not lost though. Thanks to you I've discovered a new world in GWT, and meanwhile it appears someone else has come up with a valid solution to the actual problem.
GWT is great. I highly recommend it. There's a #GWT channel on freenode if you need help.

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.