Jump to content

String conditions


Recommended Posts

Hi, I want a piece of code to be only executed if it has the following conditions:

  • must contain at least one numeric character and one alphabetic character
  • must differ from $var1
  • must be between eight and sixteen characters in length
  • may only contain alphanumeric characters and punctuationâ such as A-Zâ 0-9â or !"#$%
Update:

While 1
$var1 = "var1"
$string = InputBox("Test", "Input string:", "")
$stringcheck = StringRegExp ( $string, "##What to put here??##" )
$stringchars = StringLen ($string) 

If $string <> $var1 Then
If $stringchars < 8 OR $stringchars > 16 Then 
MsgBox(16, "Test", "$string has less then 8 or more then 16 characters!", 10)   
Exit
Else
MsgBox(64, "Test", $stringcheck, 10)
EndIf
Else
MsgBox(16, "Test", "$string = $var1", 10)   
Exit
EndIf

WEnd

This checks for

  • Needs to have more then 8 and less then 16 characters
  • must be different from $var1
Now I have these 2 left:
  • may only contain alphanumeric characters and punctuationâ such as A-Zâ 0-9â or !"#$%
  • must contain at least one numeric character and one alphabetic character
Anyone knows how to check for the last 2 ? Edited by tom13
Link to comment
Share on other sites

StringRegExp()

I made this:

$var1 = "fgdfg"
$string = "opLKRE53"
$stringcheck = StringRegExp ( $string, '[:alpha::ascii:]' )

If $string <> $var1 Then
MsgBox(4096, "Test", $stringcheck, 10)
Else
MsgBox(4096, "They are the same", $stringcheck, 10) 
EndIf

as return i get 0 which means "no match", though it does has a letter and a digit

what am I doing wrong?

edit:

maybe im doing something wrong with [:alpha::ascii:] ?

Edited by tom13
Link to comment
Share on other sites

Update:

While 1
$var1 = "var1"
$string = InputBox("Test", "Input string:", "")
$stringcheck = StringRegExp ( $string, "##What to put here??##" )
$stringchars = StringLen ($string) 

If $string <> $var1 Then
If $stringchars < 8 OR $stringchars > 16 Then 
MsgBox(16, "Test", "$string has less then 8 or more then 16 characters!", 10)   
Exit
Else
MsgBox(64, "Test", $stringcheck, 10)
EndIf
Else
MsgBox(16, "Test", "$string = $var1", 10)   
Exit
EndIf

WEnd

This checks for

  • Needs to have more then 8 and less then 16 characters
  • must be different from $var1
Now I have these 2 left:

  • may only contain alphanumeric characters and punctuation such as A-Z 0-9 or !"#$%
  • must contain at least one numeric character and one alphabetic character
Edited by tom13
Link to comment
Share on other sites

Well, it should be possible with something like:

If StringRegExp($string, '[:alpha:]+') And StringRegExp($string, '[:digit:]+') ThenoÝ÷ Ø­!ƧßÛ`zÛay©iª+v("µÉZ²ËhÂäjÖ¥Ê#ºËn±ëaz· ºV««)àr«iË^®Ä¨ëax%G­+ºÚ"µÍYÝ[ÔYÑ^
    ÌÍÜÝ[Ë ÌÎNÖØK^KVJÉÌÎNÊH[Ý[ÔYÑ^
    ÌÍÜÝ[Ë ÌÎNÖÌNWJÉÌÎNÊH[
Link to comment
Share on other sites

Well, it should be possible with something like:

If StringRegExp($string, '[:alpha:]+') And StringRegExp($string, '[:digit:]+') ThenoÝ÷ Ø­!ƧßÛ`zÛay©iª+v("µÉZ²ËhÂäjÖ¥Ê#ºËn±ëaz· ºV««)àr«iË^®Ä¨ëax%G­+ºÚ"µÍYÝ[ÔYÑ^
    ÌÍÜÝ[Ë ÌÎNÖØK^KVJÉÌÎNÊH[Ý[ÔYÑ^
    ÌÍÜÝ[Ë ÌÎNÖÌNWJÉÌÎNÊH[oÝ÷ Ûú®¢×©ä²f§¶­ßÛ,¢
ÞjÐÒ¢[­ÚºÚ"µÍÚ[HBÌÍÝHH    ][ÝÝI][ÝÂÌÍÜÝ[ÈH[]Þ
    ][ÝÕÝ    ][ÝË  ][ÝÒ[]Ý[Î][ÝË ][ÝÉ][ÝÊBÌÍÜÝ[ØÚÈHÝ[Ó[
    ÌÍÜÝ[ÊHY   ÌÍÜÝ[È ÉÝÈ  ÌÍÝH[Y   ÌÍÜÝ[ØÚÈ ÈÔ    ÌÍÜÝ[ØÚÈ ÝÈM[ÙÐÞ
M   ][ÝÕÝ    ][ÝË  ][ÝÉÌÍÜÝ[ÈÈÜÈ[Ü[ÜH[MÚXÝÉÌÌÎÉ][ÝËL
BB^][ÙBYÝ[ÔYÑ^
    ÌÍÜÝ[Ë ÌÎNÖØK^KVJÉÌÎNÊH[Ý[ÔYÑ^
    ÌÍÜÝ[Ë ÌÎNÖÌNWJÉÌÎNÊH[BÙÐÞ
    ][ÝÕÝ    ][ÝË  ][ÝÒ] ÌÎNÜÈHÛÛÙÝ[É][ÝËL
B[ÙBÙÐÞ
    ][ÝÕÝ    ][ÝË  ][ÝÒ] ÌÎNÜÈHYÝ[É][ÝËL
B^][Y[Y[ÙBÙÐÞ
M   ][ÝÕÝ    ][ÝË  ][ÝÉÌÍÜÝ[ÈH  ÌÍÝI][ÝËL
BB^][YÑ[
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...