New Built in String function(string.matches(<regular expression>))
We have introduced new string function matches for testing if the string matches a given regular expression.
This function will be useful validating a given string for particular format.
For ex, following code snippet can be used to validate a phone number string for the formats -
(123) 456 7890,
123.456.7890,
(123).456 7890
- phone = "(123) 456 7890";
- if(phone.matches("^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$") == false)
- {
- info "Please enter a valid Phone format";
- }