MikroMan Posted March 24, 2004 Share Posted March 24, 2004 :postal: Here is the sitch. When I use sniplet below and enter "12345" in the InputBox.., I get a return of one. When I enter "adbce"..., I returns 1. I maybe wrong but, is it supposed to return a zero(0) if it is not alpha and numeric. ************BEGIN SNIPLET*********************** Func Answer() Global $answer = InputBox("HostName Change", "Enter the Hostname that you want this PC to be changed to.", "", "", -1, -1, -1, -1, 30) If StringIsAlNum($answer) < 1 Then Stop() Else Verify() Blockinput(1) EndIf EndFunc ************END SNIPLET************************** Can someone verify this for me? Thanks, Russ Link to comment Share on other sites More sharing options...
redndahead Posted March 24, 2004 Share Posted March 24, 2004 (edited) If i understand the function correctly it checks for alpha and/or numeric characters. So it would return 0 on symbols like {-/!@#$%^&*}redEDIT:If you want to require to have both alpha and numeric I would do.Func Answer() Global $answer = InputBox("HostName Change", "Enter the Hostname that you want this PC to be changed to.", "", "", -1, -1, -1, -1, 30) If NOT StringIsDigit($answer) AND NOT StringIsAlpha($answer) AND StringIsAlNum($Answer) Then Stop() Else Verify() Blockinput(1) EndIf EndFuncIf you want to allow characters like {-/!#$%^&*} Then remove the AND StringIsAlNum($Answer). Edited March 24, 2004 by redndahead Link to comment Share on other sites More sharing options...
MikroMan Posted March 25, 2004 Author Share Posted March 25, 2004 Thanks Red. You basicly answered my question. My thought was that..., if you use StringIsAlpha(), then the string has to be alpha. If you use StringIsDigit()..., it has to numeric. I was looking for something that had to have alpha and numeric and not just one or the other. Do you know of a way I could force AlphaNumeric input and not just one or the other? Thanks, Russ Link to comment Share on other sites More sharing options...
scriptkitty Posted March 25, 2004 Share Posted March 25, 2004 (edited) This will force, or at least keep looping it till they give you only Alpha numeric. $test="bad" While $test="bad" $x=InputBox("test","Hi") for $i=1 to StringLen($x) select case asc(StringMid($x,$i,1))>=48 and asc(StringMid($x,$i,1))<=57; 0-9 $test="" case asc(StringMid($x,$i,1))>=65 and asc(StringMid($x,$i,1))<=90; A-Z $test="" case asc(StringMid($x,$i,1))>=97 and asc(StringMid($x,$i,1))<=122; a-z $test="" case else; anything else $test="bad" exitloop Endselect next wend msgbox(1,StringLen($x),$x) This way you could allow some extended characters by choice if you wanted as well. Edited March 25, 2004 by scriptkitty AutoIt3, the MACGYVER Pocket Knife for computers. Link to comment Share on other sites More sharing options...
redndahead Posted March 25, 2004 Share Posted March 25, 2004 Do you know of a way I could force AlphaNumeric input and not just one or the other?Maybe you missed my edit on my post, but I think the code I left up there would do it? Or am I missing something?red Link to comment Share on other sites More sharing options...
scriptkitty Posted March 25, 2004 Share Posted March 25, 2004 Red, I couldn't seem to get a change from imput with your code. I think you have a logic problem in it. If NOT StringIsDigit($answer) AND NOT StringIsAlpha($answer) AND StringIsAlNum($Answer) ThenCan this ever be true? IF not is a digit, and is all number? Slightly modified version. $x=Answer() MsgBox(1,"",$x) Func Answer() Global $answer = InputBox("HostName Change", "Enter the Hostname that you want this PC to be changed to.", "", "", -1, -1, -1, -1, 30) If NOT StringIsDigit($answer) AND NOT StringIsAlpha($answer) AND StringIsAlNum($Answer) Then Return "Working?"&@CRLF & $answer Else Return "Not working?"& @CRLF & $answer EndIf EndFunc AutoIt3, the MACGYVER Pocket Knife for computers. Link to comment Share on other sites More sharing options...
redndahead Posted March 25, 2004 Share Posted March 25, 2004 (edited) It makes sense to me granted it's not tested but here is the logicIf NOT StringIsDigit() - There could be letters and numbers and symbols, but not just numbers. AND NOT StringIsAlpha- Could be a combination of letters numbers and symbols, but not just letters. AND StringIsAlNum- This requires it to not have symbols.Am I missing something in my logic?redEdit: Can you also please point out what's different in the modified version? I can't see it. Edited March 25, 2004 by redndahead Link to comment Share on other sites More sharing options...
scriptkitty Posted March 25, 2004 Share Posted March 25, 2004 (edited) Oops, I seem to have a logic problem I need coffee or something While 1 $test=runtest(InputBox("test","Hi")) If $test<>"0" then exitloop Wend MsgBox(1,"New Password will be",$test) Func runtest($x) If StringIsDigit($x) Then MsgBox(1,"Fail","Need alpha as well") If StringIsAlpha($x) Then MsgBox(1,"Fail","Need at least one number") If NOT StringIsAlNum($x) Then MsgBox(1,"Fail","Alpha Numeric only") If NOT StringIsDigit($x) and NOT StringIsAlpha($x) and StringIsAlNum($x) Then Return $x EndFunc edit...I thought the test was does it only contain alphanumeric, not make it contain alpha and numeric elements, but not anything else. Edited March 25, 2004 by scriptkitty AutoIt3, the MACGYVER Pocket Knife for computers. Link to comment Share on other sites More sharing options...
scriptkitty Posted March 25, 2004 Share Posted March 25, 2004 BTW, here is an example of what was mixing me up: $test=0 While $test=0 $test=runtest("bob123") If $test=0 Then MsgBox(1,"test1","$test="&$test); should this display? sleep(500) Wend MsgBox(1,"New Password will be",$test) Func runtest($x) If NOT StringIsDigit($x) and NOT StringIsAlpha($x) and StringIsAlNum($x) Then Return $x EndFunc AutoIt3, the MACGYVER Pocket Knife for computers. Link to comment Share on other sites More sharing options...
MikroMan Posted March 25, 2004 Author Share Posted March 25, 2004 Maybe you missed my edit on my post, but I think the code I left up there would do it? Or am I missing something? redThanks for all the ideas. I am still unable to get it working. See code: Answer() Func Answer() Global $answer = InputBox('HostName Change', 'Enter the Hostname that you want this PC to be changed to.', '', '', -1, -1, -1, -1, 30) If NOT StringIsDigit($answer) AND NOT StringIsAlpha($answer) AND StringIsAlNum($answer) Then Stop() Else Verify() EndIf EndFunc Func Stop() MsgBox(262160, 'STOP', 'You must enter a valid hostname to continue.' & @CRLF & 'Please restart the utility and try again.', 120) Exit EndFunc Func Verify() If MsgBox(262212, 'Verify', 'You entered: ' & $answer & @CRLF & 'Is this the hostname that you wanted to enter?', 60) = 7 Then Answer() Else MsgBox(0, 'Yeehaw!', 'You HAVE enter a valid hostname.') EndIf EndFunc This is just test code, but when I just click "OK" it accepts a "Blank or Null" value. I need Alpha Numeric with no "white space" and no "Null" value. Keep the ideas coming. I have run out... Cheers, Russ Link to comment Share on other sites More sharing options...
CyberSlug Posted March 25, 2004 Share Posted March 25, 2004 (edited) You can check the string length ... AND StringLen($answer) > 0 ThenBy the way, Global $answer = InputBox('HostName Change', '.....') If @error = 1 Then MsgBox(0,"","The cancel button was clicked") Edited March 25, 2004 by CyberSlug Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig! Link to comment Share on other sites More sharing options...
scriptkitty Posted March 25, 2004 Share Posted March 25, 2004 This might help, and it is bad to call the same func from in a func. expandcollapse popup$x=answer() MsgBox(1,"hostname",$x) Func answer() While 1 Global $answer = InputBox('HostName Change', 'Enter the Hostname that you want this PC to be changed to.', '', '', -1, -1, -1, -1, 30) $test=verify($answer) If $test=$answer Then If MsgBox(262212, 'Verify', 'You entered: ' & $answer & @CRLF & 'Is this the hostname that you wanted to enter?', 60) = 7 Then Else MsgBox(0, 'Yeehaw!', 'You HAVE enter a valid hostname.') Return $answer EndIf EndIf Wend EndFunc Func verify($x) if stringlen($x)<1 then return "bad" $test="bad" While $test="bad" For $i=1 to StringLen($x) select case asc(StringMid($x,$i,1))>=48 and asc(StringMid($x,$i,1))<=57; 0-9 $test="" case asc(StringMid($x,$i,1))>=65 and asc(StringMid($x,$i,1))<=90; A-Z $test="" case asc(StringMid($x,$i,1))>=97 and asc(StringMid($x,$i,1))<=122; a-z $test="" case else; anything else $test="bad" MsgBox(262160, 'STOP', 'You must enter a valid hostname to continue.' & @CRLF & 'Please restart the utility and try again.', 120) Return "bad" Endselect next Wend If $test="" Then Return $x EndFunc Func Answer() Global $answer = InputBox('HostName Change', 'Enter the Hostname that you want this PC to be changed to.', '', '', -1, -1, -1, -1, 30) If NOT StringIsDigit($answer) AND NOT StringIsAlpha($answer) AND StringIsAlNum($answer) Then Stop() Else Verify() ; calls verify from inside answer ; more code Func Verify() If MsgBox(262212, 'Verify', 'You entered: ' & $answer & @CRLF & 'Is this the hostname that you wanted to enter?', 60) = 7 Then Answer() ; calls answer from inside verify AutoIt3, the MACGYVER Pocket Knife for computers. 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