Hello Friends,

Welcome To Infinitbility!

Sometimes, we need regex to validate user details like some patterns for example Email validation, phone number validation and many things.

Now, we are going to use regex in react native email validation.

Let’s start today article React Native Regex

What is regex

What is regex?

A regular expression is a sequence of characters that specifies a search pattern. Usually such patterns are used by string-searching algorithms for “find” or “find and replace” operations on strings, or for input validation.

React Native Regex example

React Native codebase same to javascript then syntax are same for both, we have to write and regex in veriable and use javascript test functionalities to validate.

For now we are going to validate email using regex.

validateEmail = (email) => {
    const emailRegex = /^[\w-\.][email protected]([\w-]+\.)+[\w-]{2,4}$/;

    if(emailRegex.test(email)){
        return true;
    }else{
        return false;
    }
}

On above code we create validateEmail function to validate email using regex.

Thanks for reading…