This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes HTML, CSS and JavaScript and the fly likes HTML5 field validation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "HTML5 field validation" Watch "HTML5 field validation" New topic
Author

HTML5 field validation

Wirianto Djunaidi
Ranch Hand

Joined: Mar 20, 2001
Posts: 210

I'm playing with the built in field validation for HTML5, how can we extend or hook up custom validation to the fields?

I haven't found how to do it yet, so end up not using it and using custom validation with jquery & bootstrap to maintain consistent way of displaying validation message.
Rob Crowther
author
Ranch Hand

Joined: Nov 06, 2012
Posts: 295
    
    5

Listen to the invalid event and then use setCustomValidity to display a custom message with the browser UI, or display your own custom warning message:


Read my books: Hello! HTML5 & CSS3 | HTML5 in Action | Read my blog
Wirianto Djunaidi
Ranch Hand

Joined: Mar 20, 2001
Posts: 210

I'm sorry if my original question is not clear, what I meant is how can we extend the validation by providing our own rules. Not on creating custom error message. To be specific, is there a standard way to do it rather then writing custom javascript that is not consistent with how HTML5 field validation works.

I'm not a web expert, if I understand the example correctly the callback only get calls once it failed the validation process which raise the invalid event.
Rob Crowther
author
Ranch Hand

Joined: Nov 06, 2012
Posts: 295
    
    5

Wirianto Djunaidi wrote:what I meant is how can we extend the validation by providing our own rules


OK, why don't you give some examples of the sort of rules you have in mind?

Wirianto Djunaidi wrote:if I understand the example correctly the callback only get calls once it failed the validation process which raise the invalid event.


The invalid event will be raised as part of the form submission process, or you can trigger it from a script with the checkValidity() method.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: HTML5 field validation
 
Similar Threads
Masking text fields in jquery
HTML5 for iOS and Android - Questions
Custom Validator
Validation
struts 1.? validation