Sunday 27 December 2015

Validator class

Validator class(com.liferay.portal.kernel.util.Validator) provides us some utility methods to validate data and to check format of data.

Most frequently methods are:

Validator.isNotNull(String s)
Validator.isNull(String s)

And Instead of String we can also use long value,object,array,etc..

Ex:
String countryName = "India";
if(Validator.isNotNull(countryName))
System.out.println("country name is ****"+countryName);

Validator.equals(char c1,char c2)

And Instead of char we can use double,boolean Values

Ex:
char c1 = 'a';
char c2 = 'a';
if(Validator.equals(c1,c2))
System.out.println("c1 and c2 are equal");

And also we have many important methods to validate url,uri,number,password,email address,phone numbers.
You can press ctrl+space after validator and you can check all available methods.

This Validation helps us more during server side validation.

No comments:

Post a Comment