简体   繁体   中英

Grails: How do I make a g:textfield to accept only numbers or only letters?

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

I'd use the remote-constraints plugin along with a matches constraint to enforce a regex.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM