Validating Regular Expression

How to include Regular Expression validation in a test,

Example: 1: Checking if valid email address entered in textbox. ( \b[A-Z0-9._%±]+@[A-Z0-9.-]+\.[A-Z]{2,}\b)

Example 2: Numeric Range entered in textbox [0-255]

1. Get a text from element using String text = WebUI._getText(testobject)
_2. Use String._matches _method to validate regex: text._matches(‘yourRegex’) _- true if matches, false if it does not

1 Like

The fully RFC 822 compliant regex is inefficient and obscure for validate email address because of its length. Fortunately, RFC 822 was superseded twice and the current specification for email addresses is RFC 5322. RFC 5322 leads to a regex that can be understood if studied for a few minutes and is efficient enough for actual use.

If you use HTML5, use this code:

<input type="email" name="email" required placeholder="Enter a valid email address">