Ruby + REGEX: Validate email domain -


i allow ability users create additional accounts part of company.

ie. nicky has account, , company nike. email address nicky@nike.com.

because company 'nike', i'd email addresses associates new accounts @nike.com. if tried create bob@nike.com.au, wouldn't allowed.

i'm trying find regex match nicky's domain 1 enters in new account field. if it's accepted, can create new account. otherwise, it'll throw error.

are familiar regex? shouldn't come , "i need code this: ..." without giving own input, post can come off rude. i'll answer question usage of regex though.

you can domain out of e-mail input regex this: (?<=@)([^\s]+)(?=\s|$) (doesn't work in javascript due lookbehind). see https://regex101.com/r/qx1qf5/3 examples , description.

based on answers on stackoverflow, if you're using ruby, can assume because of tags , not actual post, can capture using scan or match:

domain = emailinput.scan(/(?<=@)([^\s]+)(?=\s|$)/).first 

then compare domain name variable , answer need. doesn't seem actual "validation" part should done regex.

that's theory, anyway, , way how approach problem. go ahead , use in code , tell if works or if there problems you're encountering.


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -