What can I use to perform an email validation during entry-field accept?
Estimated Reading Time: 1 Minutes
You can use regular expressions in your entry-field to validate the contents accepted, and return an error message if necessary.
The following example shows how to declare regular expression on a screen section entry-field:
... 03 ef1 Entry-Field value var validation-regexp "^[-a-z0-9~!$%^&*_=+}{'?]+(.[-a-z0-9~! - "$%^&*_=+}{'?]+)*@([a-z0-9_][-a-z0-9_]*(.[-a-z0-9_]+)*. - "(aero|arpa|biz|com|coop|edu|gov|info|int|mil|museum|name| - "net|org|pro|travel|mobi|[a-z][a-z])|([0-9]{1,3}.[0-9]{1, - "3}.[0-9]{1,3}.[0-9]{1,3}))(:[0-9]{1,5})?$" validation-errmsg '"Invalid mail address"' validation-opts 7 ...This code will validate the message using the regluar expression, with options activated to handle it in a case insensitive manner, trimming the left and right sides of the string.
If the entry-field content doesn't match with the regexp specified by validation-regexp, then the a message box containing the validation-errmsg value is automatically displayed by the runtime and focus is kept on the field.
Matches: bob-smith@foo.com | bob.smith@foo.com | bob_smith@foo.com
Non-Matches: .smith@foo.com | smith@foo_com | bob.smith | bob.smith@foo
The regexp syntax must respect Java specifications http://docs.oracle.com/javase/8/docs/api/java/util/regex/Pattern.html.Regular Expression are collected and discussed on the web. For example, on this web site: https://www.freeformatter.com/java-regex-tester.html, you can find ready-to-use expressions for common issues as well as an online regexp validator tool.