Validator

Purpose

To validate whether a given string meets specified conditions, typically used in form field validation.

All methods in this class are static.

Usage

Judgment Validation

Directly call Validator.isXXX(String value) to validate the field and return whether it passes the validation.

For example:

boolean isEmail = Validator.isEmail("[email protected]")

Indicates whether the given string conforms to the email format.

For other validation information, please refer to the Validator class.

If the methods in Validator cannot meet your needs, you can also call

Validator.isMatchRegex("regular expression for field to be validated", "content to be validated")

to flexibly validate the content using regular expressions.

Exception Validation

In addition to manual judgment, sometimes we need to throw an exception when the condition is not met. Validator also provides an exception validation mechanism:

Validator.validateChinese("I am a paragraph of zhongwen", "Content contains non-Chinese characters");

Since the content contains non-Chinese characters, it will throw a ValidateException.