Click http://groups.google.co.in/group/javawikiforbeginners for download utility
Contains Validation classes such as Number Validator, Phone Validator and Zip Code Validator, Test cases and Test Program. You can easily use those classes in your java code, when you need some validation on Numbers, Phone and Zip.
Jar Name : - commonValidator1_0.jar
Download jar file. unzip it and use.
You can also plug-in this jar file in your eclipse environment, by adding an entry in build classpath of your project.
This project is under development, so you have to watch for more utilities or changes in existing utilities.
example:
import java.util.Locale;
import javawiki.com.validator.EMailValidator;
import javawiki.com.validator.NumberValidator;
import javawiki.com.validator.NumberValidatorRules;
import javawiki.com.validator.ValidatorException;
import javawiki.com.validator.ZipCodeValidator;
public class TestValidator
{
public static void main(String arg[])
throws ValidatorException
{
//Using Number Validator
NumberValidator num = new NumberValidator();
num.setData("$23.78");
num.setDecimalPlaces("1,2");
num.setValidatorRule (NumberValidatorRules.ALLOW_DECIMAl,
NumberValidatorRules.ALLOW_DOLLAR);
System.out.println("Number Validator - "+num.validate());
//Using ZipCode Validator
ZipCodeValidator zipValidator = new ZipCodeValidator(new Locale("IN","INDIA"));
zipValidator.setData("456434");
System.out.println("Zip Code Validator - "+zipValidator.validate());
//Using Email Validator.
EMailValidator email = new EMailValidator();
email.setData("p@@acclaris.in");
System.out.println("Verify Emai - "+email.validate());
}
}
You can also refer Test cases for Zip Code Validation.
No comments:
Post a Comment