ray306 Posted February 24, 2007 Posted February 24, 2007 Hi: I'm trying to validate a U.S. zip code in either 5digit or zip+4 format It appears to me to be accurate but it is not working. Here is the code: CODE$_zip = GUICtrlRead ($Czip ) If $_zip = "" Then;Means this is a required field $errStr = $errStr & "Zip is a Required Field"&@cr $errCount += 1 GUICtrlSetColor($CLabel7, 0xff0000) ElseIf Not (StringRegExp ( $_zip , "[0-9]{5}|([0-9]{5}[\-]{1}[0-9]{4})" ,0)) Then $errStr = $errStr & " Invalid Zip. Use Either NNNNN or NNNNN-NNNN Format"&@cr GUICtrlSetColor($Czip, 0xff0000) $errCount += 1 Endif Any ideas? Thanks Ray306
Xenobiologist Posted February 24, 2007 Posted February 24, 2007 Hi, should be easy. You have a string and want to check whether it is a correct zip code? I dunno the USA zip codes how do correct ones look? So long, Mega Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times
Thatsgreat2345 Posted February 24, 2007 Posted February 24, 2007 Its because it will find a match on the first part even though is a 4 digit behind it or anything else, you have to use the $ to mark make sure its the end of the line something like StringRegExp($_zip, "[0-9]{5}$|[0-9]{5}[\-]{1}[0-9]{4}$",0)
Moderators SmOke_N Posted February 24, 2007 Moderators Posted February 24, 2007 (edited) $sString = "15697" If _IsValidZip($sString) Then MsgBox(64, 'Info1', 'Works') $sString = "15697-2345" If _IsValidZip($sString) Then MsgBox(64, 'Info2', 'Works') Func _IsValidZip($sString) Return StringRegExp($sString, "^\d{5}(\s*[\-]\s*\d{4})?$") EndFuncEdit: Took care of a possible space issue between the hyphen and numbers of zip. Edit2: Edited the edit, I didn't notice you were already using GUICtrlRead() Edited February 24, 2007 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.
ray306 Posted February 25, 2007 Author Posted February 25, 2007 Thanks folks, Works like a charm....I clearly didn't understand the use of $ Ray306
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