Dharmin Patel
Dharmin Patel

Reputation: 3

React Native email validation without regex

I want to validate an email address in react-native TextInput, but without using regex. I want to validate it by the native way, like in html, where we can do it by defining input type="email".

Upvotes: 0

Views: 2487

Answers (1)

dmuensterer
dmuensterer

Reputation: 1885

I suggest taking a look at libraries like validate.js.

A completely native way like <input type="email>" is not available within React Native. Regex is indeed problematic for email addresses as there are incredibly many cases and any regular expressions will very likely cause false positives or vice versa. The official RFC822 regex is extremely obscure and slow. Good validation libraries use BNF Parsers to make this process more efficient.

As a security engineer I need to point out though, that front-end validation is never enough, no matter how good it is.

Requests can easily be forged which makes backend validation mandatory for all cases. Just send an email to the provided address and require the user to click a unique link in it that you map to a validationCompleted call in your app.

Upvotes: 1

Related Questions