searching a string for a number

Homepage Clovertech Forums Read Only Archives Cloverleaf Tcl Library searching a string for a number

  • Creator
    Topic
  • #51555
    Kevin Crist
    Participant

    I am trying to validate test codes and making sure they dont have numbers in them. i have tried the following commands with no luck:

    {[string is digit -strict $testCode]}

    and

    if {![regexp -all {[^0-9]} $testCode]} {

    set errormsg “WARN: ORM Killed – Numeric test code: $patientAcct,

    $parent/$placerid/$fillerid, $dept/$testCode/$priority,$ordertype/$orderStatus”

    set actionFlag “KILL”

    }

    They only work if the whole test code is a number, i was hoping that it would work if only at least one character is a number. So i guess in a sense it is working but what do i have to add to search for any number?

    Thanks.

Viewing 1 reply thread
  • Author
    Replies
    • #70761
      David Barr
      Participant

      This should work:

      Code:

      if {[regexp {[0-9]} $testCode]} {

    • #70762
      Tom Rioux
      Participant

      Try this:

      {[string is alpha -strict $testCode]}

      That will return a 1 if it is all alphabet characters and will return a 0 if there are any numbers in the string.

      Or if you want to use regexp, try this since all you want is alpha characters.  

      regexp {^[A-Z]*$} $var

      Hope this helps…

      Tom Rioux

Viewing 1 reply thread
  • The forum ‘Tcl Library’ is closed to new topics and replies.

Forum Statistics

Registered Users
5,129
Forums
28
Topics
9,301
Replies
34,447
Topic Tags
288
Empty Topic Tags
10