jvanegmond Posted May 14, 2006 Share Posted May 14, 2006 I'm trying to check if string is a email adres so i use: [a-z]@[a-z.a-z][a-z.a-z.a-z] That makes sence to me because then it'll also be capable of doing bla@bla.co.uk and bla@bla.com but .. [a-z]@[a-z.a-z] also accepts the same 2 values. Why? and shouldn't i also use the @ in between tags? Here's my quick test code, pretty handy. Local $sPattern = "[a-z]@[a-z.a-z][a-z.a-z.a-z]", $sTest = "email@adres.com", $vResult, $nFlag While 1 $sPattern = InputBox("StringRegExp Sample", "What is the PATTERN to test?", $sPattern) $sTest = InputBox("StringRegExp Sample", "What is the LINE to test?", $sTest) $vResult = StringRegExp($sTest, $sPattern) Select Case @Error = 2 ; Error. The pattern was invalid. $vResult = position in $sPattern where error occurred. Msgbox(0, "" , "Error invalid pattern") Case @Error = 0 if @Extended Then ; Success. Pattern matched. $vResult matches @Extended Msgbox(0, "" , "Match") Else ; Failure. Pattern not matched. $vResult = "" Msgbox(0, "" , "No Match") EndIf EndSelect WEnd github.com/jvanegmond Link to comment Share on other sites More sharing options...
Simucal Posted May 14, 2006 Share Posted May 14, 2006 Try using something like: [a-zA-Z0-9_\\.-]+@[a-zA-Z0-9\-]+\.+[a-zA-Z0-9]{2,4} You werent using an quantifiers after your classes. Like +, *, etc. Also, your regexp would only allow lowercase, letter only emails. This will take numbers, dashes, underscores, upper/lowercase, and addresses like bla@bla.co.uk I havent tested it thorougly so it might take some tweaking. AutoIt Scripts:Aimbot: Proof of Concept - PixelSearching Aimbot with several search/autoshoot/lock-on techniques.Sliding Toolbar - Add a nice Sliding Toolbar to your next script. Click the link to see an animation of it in action!FontInfo UDF - Get list of system fonts, or search to see if a particular font is installed.Get Extended Property UDF - Retrieve a files extended properties (e.g., video/image dimensions, file version, bitrate of song/video, etc) Link to comment Share on other sites More sharing options...
jvanegmond Posted May 14, 2006 Author Share Posted May 14, 2006 (edited) [a-zA-Z0-9_\\.-]+@[a-zA-Z0-9\-]+(\.+[a-zA-Z0-9]){,1} Would this mean only email adresses ending with a .com or .co.uk come through but Not "" (empty) or .co.uk.co ? Edited May 14, 2006 by Manadar github.com/jvanegmond Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted May 14, 2006 Moderators Share Posted May 14, 2006 (edited) I don't know how much I trust this to actually prove it's a valid email address (StringRegExp that is), without actually using "All (Oh my ) proper email extensions", but you could try this, I couldn't get Simucals to work right for some reason:$email = 'abdc@myemail.co.uk' $Check = StringRegExp($email, '^[_A-Za-z0-9-]+(\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\.[A-Za-z0-9-]+)*(\.[A-Za-z]{2,4})', 3) If @extended Then MsgBox(0, 'Info:', 'Is a valid email') Else MsgBox(64, 'Info:', 'Is not a valied email') EndIf Edit: Doesn't solve your ".co.uk.co" issue. Edited May 14, 2006 by SmOke_N Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
Simucal Posted May 14, 2006 Share Posted May 14, 2006 (edited) I couldn't get Simucals to work Weird. This didnt work for you? $email = 'simucal@gmail.com' $Check = StringRegExp($email, '^[a-zA-Z0-9_\\.-]+@[a-zA-Z0-9\-]+\.+[a-zA-Z0-9]{2,4}', 0) If @extended Then MsgBox(0, 'Info:', 'Is a valid email') Else MsgBox(64, 'Info:', 'Is not a valied email') EndIf I tried a few email addresses and it seems to work fine. EDIT: Hey smoke, you used the "^" character in your regexp at the begining.. I assume that is to indicate match at the begining of the string. Has that feature been implemented yet? Edited May 14, 2006 by Simucal AutoIt Scripts:Aimbot: Proof of Concept - PixelSearching Aimbot with several search/autoshoot/lock-on techniques.Sliding Toolbar - Add a nice Sliding Toolbar to your next script. Click the link to see an animation of it in action!FontInfo UDF - Get list of system fonts, or search to see if a particular font is installed.Get Extended Property UDF - Retrieve a files extended properties (e.g., video/image dimensions, file version, bitrate of song/video, etc) Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted May 14, 2006 Moderators Share Posted May 14, 2006 Weird. This didnt work for you? $email = 'simucal@gmail.com' $Check = StringRegExp($email, '^[a-zA-Z0-9_\\.-]+@[a-zA-Z0-9\-]+\.+[a-zA-Z0-9]{2,4}', 0) If @extended Then MsgBox(0, 'Info:', 'Is a valid email') Else MsgBox(64, 'Info:', 'Is not a valied email') EndIf I tried a few email addresses and it seems to work fine. EDIT: Hey smoke, you used the "^" character in your regexp at the begining.. I assume that is to indicate match at the begining of the string. Has that feature been implemented yet?I've used it a few times in the past, I don't know to be honest. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
neogia Posted May 15, 2006 Share Posted May 15, 2006 Well, this script takes about ~.5sec for a valid email and ~1sec for an invalid(timeout) email. It actually does a DNS lookup on the domain. It's not 100% because there's no feasible way to check the username with the domain name, so someone could supply jowerhaoiuoiugoijweoir@gmail.com, and it would be valid(I checked, it's not ) However, they can't send i'm^an@$$@hotmail.com, that will most definitely fail. So I'd say this method is about 85% accurate. $email = InputBox("Input", "Email Address:") $Check = StringRegExp($email, '[_A-Za-z0-9-]+(?:\.[_A-Za-z0-9-]+)*@([A-Za-z0-9-]+(?:\.[A-Za-z0-9-]+)*(?:\.[A-Za-z]{2,4}))', 1) If @extended Then $domain = $check[0] Else MsgBox(0, 'Info:', $email & ': is not valid') Exit EndIf $pid = Run("nslookup -type=MX " & $domain,"","",7) While ProcessExists($pid) Sleep(100) WEnd $bFound = 0 If StdoutRead($pid,0,true) > 0 Then $msg = StringSplit(StdoutRead($pid), @CRLF) For $line in $msg If StringInStr($line, $domain) == 1 Then $bFound = 1 EndIf Next EndIf If $bFound == 1 Then MsgBox(0, 'Info:', $email & ': is a valid email') Else MsgBox(64, 'Info:', $email & ': is not a valid email') EndIf P.S. Oh, and there's no ~1sec delay if the email is formatted incorrectly, that's instantaneous; at least to us humans. [u]My UDFs[/u]Coroutine Multithreading UDF LibraryStringRegExp GuideRandom EncryptorArrayToDisplayString"The Brain, expecting disaster, fails to find the obvious solution." -- neogia Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now