O'Reilly logo

PrimeFaces Beginner's Guide by K. Siva Prasad Reddy

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action – client-side e-mail validation

In our Registration Form, we can do some basic e-mail format validation on client side itself thereby reducing the server roundtrip. We can create a JavaScript function to validate e-mail using Regex, and then hook it up with the onchange event on e-mail input field. Perform the following steps for the same:

  1. Write a JavaScript function to validate e-mail address:
    function validateEmail() { var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/; var email = $.trim($("#userForm\\:email").val()); if(email ==''){ $("#userForm\\:emailMsg").text(""); $("#userForm\\:emailMsg").attr("class", ""); return; } if( emailReg.test( email ) ) { $("#userForm\\:emailMsg").text("Valid Email"); $("#userForm\\:emailMsg").attr("class", ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required