Jump to content
Thomymaster

Another RegExp question

Recommended Posts

Thomymaster

Hi

 

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

9

9,1

9.2

 

Everything else shouldn't be allowed.

 

Best,

Thomas

 

Share this post


Link to post
Share on other sites
kylomas

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

Share this post


Link to post
Share on other sites
jguinch

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

 

Share this post


Link to post
Share on other sites
Thomymaster

Thats works fine, thanks a lot :)

Share this post


Link to post
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

×