Hospital Number Validation

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf Hospital Number Validation

  • Creator
    Topic
  • #53478
    David Harrison
    Participant

      My brain’s not working – it’s an age thing!!

      I want to validate hospital numbers as either 6 numerics or 6 numerics preceded by either A or V. There must be a neat way of doing this.

      Thanks,

      Dave

    Viewing 3 reply threads
    • Author
      Replies
      • #77825
        Keith McLeod
        Participant

          if [regexp — {[AV]{0,1}d{6}} [lindex $xlateInVals 0] {}] {

           do something

          }

          This might work for you….

        • #77826
          David Harrison
          Participant

            Thanks,

            It doesn’t but this does

            Code:

            set distno [lindex $xlateInVals 0]
            if {([expr [string length $distno]] == 6 && [string is digit -strict $distno]) || ([regexp {^[A|V][0-9]} $distno] && [expr [string length $distno]] == 7 ) } {
             …
            }

          • #77827
            Eric Fortenberry
            Participant

              I think the only problem (for your situation) with Keith’s solution is that it is not anchored to the beginning and end of the line (by using “^” and “$” respectively).  Just for kicks, here is my try at a solution:

              Code:

              if {[regexp — {^[AV]?d{6}$} [lindex $xlateInVals 0] {}]} {
                     # do something
              }

              Thanks,

              Eric

            • #77828
              David Harrison
              Participant

                Eric,

                That works and it’s a tad more elegant than mine.

                Thanks,

                Dave

            Viewing 3 reply threads
            • The forum ‘Cloverleaf’ is closed to new topics and replies.