New Built in String function(string.matches(<regular expression>))

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, 1234567890, (123)-456-789, (123) 456 7890, 123.456.7890, (123).456 7890
  1. phone = "(123) 456 7890";
  2. if(phone.matches("^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$") == false)
  3. {
  4. info "Please enter a valid Phone format";
  5. }