1701905578

The 5 parts to creating a successful email validation Regex


1. **name** : One or more alphanumericla characters, undescores, dashes, or dots 2. **@** : Literal character 3. **domain** : One or more alphanumerical characters, undescores, dashes, or dots 4. **.** : Literal dot 5. **extension** : One or more alphanumerical charactes, undescores, dashes, or dots Putting it all together: ```javascript let emailPattern = /([a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z0-9._-]+)/g; let validEmail = "maaike_123@email.com"; let invalidEmail = "maaike@mail@.com"; console.log(validEmail.match(emailPattern)); console.log(invalidEmail.match(emailPattern)); ``` I found this code very simple but very practical to use in small applications.

(0) Comments

Welcome to Chat-to.dev, a space for both novice and experienced programmers to chat about programming and share code in their posts.

About | Privacy | Terms | Donate
[2024 © Chat-to.dev]