Ok, it works!!  Thanks to everyone for their suggestions and answers.  This
group is a great resourse.  Thanks again!!!!

...Brad


"Brad Melendy" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> Thanks James,
> I tried a regular expression comparison first, but it was eluding me.  I'm
> new to PHP (trying to convert form ASP) and part of this is me trying to
> convert my ASP/VBSCRIPT to PHP.  ;-)  I actually have a FOR loop evaluated
> when the conditions of the IF statement are met, and I suspect that is
> messing things up.  Here's my entire code and I've used your expression
> comparison instead but it still fails to find the "-" unless I split
things
> up and check either ONLY for the '-' at the beginning or the end, but not
> both in the same line:
>
>  function StringCheck($sString)
>  {
>  if (preg_match("/^-|-$/s", $sString))
>   {
>   for ( $counter=0; $counter < strlen($sString); $counter++ )
>    {
>    $nChar = ord(strtolower(substr($sString, $counter, 1)));
>    if (($nChar > 47 And $nChar < 58) or ($nChar > 96 And $nChar < 123) or
> ($nChar == 45))
>     {
>     $result = TRUE;
>     }
>    else
>     {
>     $result = FALSE;
>     break;
>     }
>    }
>   }
>  else
>   {
>   $result = FALSE;
>   }
>  return $result;
>  } //End Function StringCheck
>
>
> Maybe you see something I don't.  I can't get over the fact that if I
check
> for just the front, or the end, it works, but if I check for both the
front
> and end of the string in the same line with the OR, it fails.  :-\  Thanks
> in advance for any thing you might notice.
>
> ....Brad
>
> "Yz James" <[EMAIL PROTECTED]> wrote in message
> [EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> > Hi Brad,
> >
> > This worked for me:
> >
> > <?
> >
> > if ((substr($sString, 0, (strlen($sString)-1) == "-")) ||
> (substr($sString,
> > 0, 1) == "-")) {
> >  echo "you can't have a dash at the beginning or end of your string.";
> > }
> >
> > ?>
> >
> > ...... but I'd tend to go for a regex as a solution to what you're
after,
> > which involves less code:
> >
> > <?
> >
> > if (preg_match("/^-|-$/s", $string)) {
> >  echo "You cannot have a \"-\" character at the beginning or end of your
> > string.";
> > } else {
> >  echo "Whatever....";
> > }
> >
> > ?>
> >
> > Just my thoughts...
> >
> > James
> >
> > "Brad Melendy" <[EMAIL PROTECTED]> wrote in message
> > [EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> > > Hello,
> > > Ok, this works:
> > >
> > > if (substr($sString,(strlen($sString)-1)!="-")) {
> > > print "You can't have a dash at the end of your string.";
> > > }
> > >
> > > and this works:
> > > if (substr($sString,0,1)!="-") {
> > > print "You can't have a dash at the beginning of your string.";
> > > }
> > >
> > > But, this doesn't work for any case:
> > > if ((substr($sString,(strlen($sString)-1)!="-")) or
> > > (substr($sString,0,1)!="-")) {
> > > print "you can't have a dash at the beginning or end of your string.";
> > > }
> > >
> > > What could be wrong?  I've used a logical OR operator in the middle of
> an
> > IF
> > > statement like this before, but for some reason, this just isn't
> working.
> > > Anyone got any ideas?  I suppose I can just evaluate this with two
> > different
> > > IF statements, but it seems like I shoud be able to do it in one and
> > reduce
> > > duplicate code.  Thanks very much in advance.
> > >
> > > .....Brad
> > >
> > >
> > >
> >
> >
>
>



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to