Validating Patterns with Regular Expressions

Learn how to validate fields against a custom format using regular expressions.

We'll cover the following

Regular expressions define search patterns that can be used for validation purposes. In this lesson, we will show how to validate a currency input to match our custom format. We will create a field prizeMoney to store the total earnings of the player. The entered value has to follow the $#,###,### format. Values that do not match this format will result in a validation error.

First step is to create the field for prize money along with the getter and setter methods.

Level up your interview prep. Join Educative to access 80+ hands-on prep courses.