Jump to content

Another RegExp question


Recommended Posts

Thomymaster,

One solution...

local $sString = '9.0,1,3'

if stringregexp($sString,'[^\d\.\,]') then
    ConsoleWrite('Invalid String' & @CRLF)
Else
    ConsoleWrite('Valid String' & @CRLF)
endif



; or shorthand version

ConsoleWrite((stringregexp($sString,'[^\d\.\,]') ? 'Invalid' : 'Valid') & ' string' & @CRLF)

kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Link to comment
Share on other sites

Does anybody of you have a hint for me on how to check this:

I have a string that should only contain digits (0-9) a optionally comma "," or a dot "."

So, are "1." or ".1" or "1.2.3" good or not ?

Local $aStrings[7] = [ "something", "05", "1.2", "1.", ".3", "10.2", "12.2,3"]

For $i = 0 To UBound($aStrings) - 1
    ConsoleWrite($aStrings[$i] & " : ")
    If StringRegExp($aStrings[$i], "^\d+([,.]\d+)?$") Then
        ConsoleWrite("good" & @CRLF)
    Else
        ConsoleWrite("not good" & @CRLF)
    EndIf
Next

 

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