LiveCode for FM Manual Validation and CheckingHow do I validate an email address?

How do I validate an email address?

Field Validation

It is easy to make a mistake while entering an email address. With LCEval we can return the value of the matchText function which tests a string against a regular expression. Regular expressions are often a little tricky to comprehend but luckily there's a website devoted to email validating regular expressions. The one we will use in this example is `General Email Regex (RFC 5322 Official Standard)`.

Create a table with a text field and click the `Options...` button to open the `Field Options` dialog.

Field Options

On the `Validation` tab of the field options dialog check `Validated by calculation` and `Display custom message if validation fails` and enter in a message you would like users to see. Then click the `Specify...` button to specify the calculation to determine if the field value is valid.

LCEval

Set the calculation to the following script and click `OK`.

LCEval ( "matchText( fmParam(1), \"(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|\" & quote & \"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\[\x01-\x09\x0b\x0c\x0e-\x7f])*\" & quote & \")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])\")"
; Email )

Testing

Click `OK` to close all the open dialogs and switch into `Browse` mode to test the validation.

1 Comments

Mark Waddingham

Can we rename this to just 'How do I validate an email address?'

Add your comment

E-Mail me when someone replies to this comment