Jump to content

Exceptions for StringIsAlpha and StringIsDigit


Recommended Posts

First of, I assume StringIsAlpha means any letter and StringIsDigit means any number. If I'm wrong correct met.

Anyway, I want them to ignore ".", on first glance there isn't any additional parameters, but I'm certain there is away.

Real Quick Exmaple:

If StringIsAlpha($Host) Then
        $HostType = "Address" ; www.google.com.au
    ElseIf StringIsDigit($Host) Then
        $HostType = "IP" ; 127.0.0.1
    Else
        $HostType = "Invalid"
    EndIf

At the moment they don't ignore the ".".

Edited by FinalVersion
Link to comment
Share on other sites

$result = StringInStr($Host, ".")

check to see if its true and then if it is, you can ignore it.

EDIT: you can also stringtrim if you still need the other data in the string.

Edited by t0ddie

Valik Note Added 19 October 2006 - 08:38 AMAdded to warn level I just plain don't like you.

Link to comment
Share on other sites

Forgive me if I'm wrong, but all that tells me is if it contains a ".". And honestly I don't see how that helps, correct me though, it's really late :mellow:

i don't understand what you mean by wanting to "ignore" it.

$result = StringInStr($Host, ".")
if $result = 1 then
;ignore or do nothing
else
If StringIsAlpha($Host) Then
        $HostType = "Address" ; www.google.com.au
    ElseIf StringIsDigit($Host) Then
        $HostType = "IP" ; 127.0.0.1
    Else
        $HostType = "Invalid"
    EndIf
endif

i nested the if statement here just to show you an example quickly but there are better ways to code this.

EDIT: are you trying to simply remove the "." from the strings?

Edited by t0ddie

Valik Note Added 19 October 2006 - 08:38 AMAdded to warn level I just plain don't like you.

Link to comment
Share on other sites

  • Moderators

FinalVersion,

Just remove any "." characters from the test string with StringReplace before you test with StringIsAlpha/Digit. :mellow:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

It's a GUI with an input box (My fault for not mentioning that), that would be to confusing.

Also I'm not trying to remove them, basically I want to ignore if there is a "." in the string, StringIsAlpha would still be true and the same for StringIsDigit.

Edited by FinalVersion
Link to comment
Share on other sites

you could save a new variable where you remove the "." then check the other parameters of that new variable against your alpha and digit that way the old variable can still be used and you did not remove anything.

Valik Note Added 19 October 2006 - 08:38 AMAdded to warn level I just plain don't like you.

Link to comment
Share on other sites

  • Moderators

Finalversion,

t0ddie understood perfectly - just create a new variable for testing purposes and leave the original alone.

Go and get some sleep - it sounds like you need it! :(

M23

Edit: I see the penny dropped! Sleep well! :mellow:

Edited by Melba23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Not yet :mellow: Must finish this, I'm determ.... zzzz

Anyway after that powernap.

$String = "www.google.com.au"
$Result = StringReplace($String, "", ".")

MsgBox(0, "Hey", $Result)

I have no idea what to put for "searchstring/start" (2nd parameter). "The substring to search for or the character position to start the replacement." Make no sense at the moment to me.

Link to comment
Share on other sites

yes and glad i could help i usually ask questions on here but hey why not answer some too right? i have been here long enough. even though you are falling asleep it still counts as me helping hahaha

Valik Note Added 19 October 2006 - 08:38 AMAdded to warn level I just plain don't like you.

Link to comment
Share on other sites

Indeed, last problem I swear. Let's say they don't enter a "." (they just enter gibberish), what can I do about that?

; Declare some variables
    Local $HostType
    Local $ReplaceResult = StringReplace($Host, ".", "")

    ; Check If Required Fields Are Filled Out Etc

    If StringIsAlpha($ReplaceResult) Then
        $HostType = "Address"
    ElseIf StringIsDigit($ReplaceResult) Then
        $HostType = "IP"
    Else
        $HostType = "Invalid"
    EndIf

    MsgBox(0, "", $HostType)
Link to comment
Share on other sites

well you can only make code to a certain extent to be user friendly or "idiot proof"

you can make a custom error message so when the data that they try to use does not work i.e. the host does not load... you can tell them to check what they entered and re-enter it.

other than that you are going to have to do a series of things.

check to make sure the length is correct so that anything over or under a certain number is rejected.

check if there are symbols in it obviously with alpha and digit.

as for a typo in the numbers or digits there is nothing you can do about that.

but you can certainly detect this

dslkj

or this 1234.5432.1234.5432

or this 123.54.6*.234

Valik Note Added 19 October 2006 - 08:38 AMAdded to warn level I just plain don't like you.

Link to comment
Share on other sites

but you can certainly detect this

dslkj

or this 1234.5432.1234.5432

or this 123.54.6*.234

How?

As for the typo, lets say they missed typed google.com, after the program tries to connect, and fails. I'll throw something at them(a dictionary).

Edited by FinalVersion
Link to comment
Share on other sites

How?

As for the typo, lets say they missed typed google.com, after the program tries to connect, and fails. I'll throw something at them(a dictionary).

first two are improper length.

check to see what length the smallest and biggest valid strings are

any string over or under that you can throw an error.

third one is a symbol was entered.

you can check to see if its neither alpha or digit then you know there is a symbol or space in it.

first eliminate the spaces just like you eliminated the "."

then you can use a loop to check the length of the string, save it into a new variable, trim the new variable one character at a time and keep checking it until you find the culprit. then display it and say HEY! you see this? you cant do that! or something.

Valik Note Added 19 October 2006 - 08:38 AMAdded to warn level I just plain don't like you.

Link to comment
Share on other sites

ok fine i will be nice

ip only is easy but a website can be any length

first you remove the "." AND the " " from the $Host variable.

also to avoid problems with the :// symbols you want to remove http://

then check if its a number or letters seperately and then check its length.

the length should be 9 for this and that should be your minimum for numbers

the length of a minimum website like www.a.com is 7 and you can set max at whatever you want.

$Host = "ertuh4r432#5340958734587" 


$ReplaceResult = StringReplace($Host, ".", "")
$ReplaceResult = StringReplace($ReplaceResult, " ", "")
$ReplaceResult = StringReplace($ReplaceResult, "http://", "")
$len = stringlen($ReplaceResult)

If StringIsDigit($ReplaceResult) Then
if $len < 9 then
msgbox(0,"test","error... too short")
exit
endif
if $len > 9 then
msgbox(0,"test","error... too long")
exit
else
        $HostType = "IP"
endif
endif

If StringIsAlpha($ReplaceResult) Then
if $len < 7 then
msgbox(0,"test","error... too short")
exit
endif
if $len > 100 then
msgbox(0,"test","error... too long")
exit
else
        $HostType = "Address"
endif
endif


Do
        $ReplaceResult2 = stringtrimleft($ReplaceResult,$len - 1)
if not StringIsAlNum($ReplaceResult2) Then
    msgbox(0,"test",$ReplaceResult2 & " Is not allowed")
exit
endif
    $ReplaceResult = stringtrimright($ReplaceResult,1)
    $len = $len - 1
until $len = 0

I think it should work for the most part the coding may be slightly sloppy haha

Edited by t0ddie

Valik Note Added 19 October 2006 - 08:38 AMAdded to warn level I just plain don't like you.

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...