I think many people have done some similar development tasks before:
I would like to check the people’s email address whether only match @tomtom.com or @stream.com.
Currently, I have two solutions in my mind:
-
Using
indexof()functionvar checkTomTomEmail=eo.data.username.indexOf("@tomtom.com"); var checkStreamEmail=eo.data.username.indexOf("@stream.com"); if (checkTomTomEmail >0 || checkStreamEmail >0 ) { //Run the login code } Else { //Please login with your tomtom or stream email } -
Using match
var patt1=/@tomtom.com/gi; var patt2=/@stream.com/gi; var checkTomTomEmail=eo.data.username.match(patt1); var checkStreamEmail=eo.data.username.match(patt2); if(indexOf(checkTomTomEmail)> 1 ||indexOf (checkStreamEmail)>1) { //Login }
I still think I do not consider all the detail yet. Any suggestions?
Thanks
Perhaps if people are only allowed to enter emails for those two addresses you should only collect the username and then allow them to choose @tomtom.com or @stream.com using radiobuttons.
If you still want to go the javascript route then your regex can be combined into a single statement