views:

39

answers:

1

I have different g:textfields throughout my code, and I want to make some of the to only accept numbers or letters, but I don't want to validate for them, I want them to be immediate, like if the textfield does not accept numbers when I try to write one nothing should happen.

Thanks in advance!

FG

+1  A: 

I'd use the remote-constraints plugin (http://grails.org/plugin/remote-constraints) along with a matches constraint to enforce a regex: http://www.grails.org/doc/latest/ref/Constraints/matches.html

It will validate when the user tabs off the fields and display an error. It will also stop invalid data being saved on the server side.

If you want to stop them actually typing a non alpha numeric character all together, you'll need to write a custom onKeyPress function for your input fields.

cheers

Lee

leebutts
I have three different textfields and not related to each other.
fgualda87
Two of them should accept only numbers, and one should accept only characters. I wanna do this dynamically, not through a submit button.
fgualda87
The remote contstraints plugin validates when you tab off the field, is that not what you mean by dynamic? If you don't have a domain object you can use, create a command object with the fields and the required constraints.
leebutts