Re: Regular Expression question

From: Glenn Jackman (xx087_at_freenet.carleton.ca)
Date: 04/12/04


Date: 12 Apr 2004 18:22:16 GMT

Justin Miller <grayghostx@yahoo.com> wrote:
> <range> ::= <digit|real>-<digit|real>
> <digit> ::= 0-9
> <real> ::= <digit>.<digit>
>
> As an example, the input could be a range like: 4-12
> Or it could be in the form of floats: .5-1.7
>
> The form where you have normal integers is trivial, but I also want it
> to be able to validate that, in the case of the real number example,
> that the user didn't simply enter a period by itself. You can have 1.,
> .1, 1.5, etc. Just not a single period.

My regex would be: (\d+(?:\.\d*)?|\.\d+)-(\d+(?:\.\d*)?|\.\d+)

    # a number is:
    # some digits followed optionally by a dot and maybe more digits
    # or a dot followed by some digits
    set number {\d+(?:\.\d*)?|\.\d+}
    
    # a range is a number followed by a hyphen followed by a number
    set range "($number)-($number)"

    regexp $range ".5-1.7" -> low high

-- 
Glenn Jackman
NCF Sysadmin
glennj@ncf.ca


Relevant Pages

  • Re: How do I validate these fields
    ... digits is entered ... Validate by calculation: length= 4 ... "validate for 4 digit year". ... FileMaker Konferenz in Zürich Mai 2010 ...
    (comp.databases.filemaker)
  • help with cobol date
    ... I am trying to accept a date and validate it against today's date. ... I am getting the user to enter a date - 8 digits ddmmyyyy. ... date is comming out as YYMMDD, ... Is there a simplier way to check that the users date is less than ...
    (comp.lang.cobol)
  • Re: trouble with replace
    ... What I want to do is remove all Currency ... >symbols so that I can validate the number. ... I am in South Africa and so ... followed by exactly two digits it is most unwise just to remove the ...
    (microsoft.public.scripting.jscript)
  • Re: How do I validate these fields
    ... digits is entered ... Validate by calculation: length= 4 ... "validate for 4 digit year". ... FileMaker Konferenz in Zürich Mai 2010 ...
    (comp.databases.filemaker)
  • How do I validate these fields
    ... FMPro10adv. ... Vista ... I have 2 fields I would like to validate. ... This is a text field and we input numbers but they must be 4 digits ...
    (comp.databases.filemaker)