checking for alpha in a string

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Abby Lee

    #1

    checking for alpha in a string

    {
    if (str.length != 3)
    return false;
    else if (str.charAt(0) != [a-z])
    return false;
    else if (!Is_Digit(str. charAt(1)))
    return false;
    else if (!Is_Digit(str. charAt(2)))
    return false;
    else return true;
    }

    The problem seems to be with the following line...comment it out and the rest
    works.
    else if (str.charAt(0) != [a-z])
  • Amir Hardon

    #2
    Re: checking for alpha in a string

    Abby Lee wrote:
    [color=blue]
    > {
    > if (str.length != 3)
    > return false;
    > else if (str.charAt(0) != [a-z])
    > return false;
    > else if (!Is_Digit(str. charAt(1)))
    > return false;
    > else if (!Is_Digit(str. charAt(2)))
    > return false;
    > else return true;
    > }
    >
    > The problem seems to be with the following line...comment it out and the
    > rest works.
    > else if (str.charAt(0) != [a-z])[/color]
    Try:

    else if(str.charAt(0 )!="[a-z]")
    --
    Remove the 'dont_spam_me' and the dashes before mailing me.

    Comment

    • Mick White

      #3
      Re: checking for alpha in a string

      Amir Hardon wrote:
      [color=blue]
      > Abby Lee wrote:
      >
      >[color=green]
      >>{
      >> if (str.length != 3)
      >> return false;
      >> else if (str.charAt(0) != [a-z])
      >> return false;
      >> else if (!Is_Digit(str. charAt(1)))
      >> return false;
      >> else if (!Is_Digit(str. charAt(2)))
      >> return false;
      >> else return true;
      >>}
      >>
      >>The problem seems to be with the following line...comment it out and the
      >>rest works.
      >>else if (str.charAt(0) != [a-z])[/color]
      >
      > Try:
      >
      > else if(str.charAt(0 )!="[a-z]")[/color]
      Try:
      {
      return /^[a-z]\d{2}$/i.test(str);

      }

      Alpha Digit Digit
      Mick








      Comment

      Working...