Jump to content


regular expresions


5 replies to this topic

#1 joe

    Young Padawan

  • Members
  • Pip
  • 115 posts
  • Location:stuck in the middle of cyber space

Posted 16 May 2006 - 12:43 PM

hi, everbody.... :P
i've got stuck on this regex.
<?
$teks="teks123";
$pattern="^[a-zA-Z]";

if(eregi($pattern,$teks))
{
echo "Teks is valid>";
}
else
{
echo "Teks isn't valid.";
}
?>

my question is : i want to filter only for charcter. But, when i run that script, i've got : Teks is valid. :wacko:
i want that '$teks' can't come in into my aplications.
Pliz, help and correct me..... :D :D

Thans B4.......

#2 HaloprO

    Requires Armed Escort

  • Members
  • PipPip
  • 310 posts
  • Gender:Male
  • Location:California, USA

Posted 16 May 2006 - 01:50 PM

$pattern="^[a-zA-Z]$";
^ means beginning of string
$ means end of string
So: starts with [a-zA-Z] and ends with [a-zA-Z]

#3 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 16 May 2006 - 05:44 PM

Not to be picky or anything, but that actually means everything from start to finish is only [a-zA-Z]. Not just the first and last characters. Also, since you're using eregi, as opposed to ereg, you don't need the capital letters.

I'd love to offer some actual help, but i don't understand what you mean by "come in."

#4 joe

    Young Padawan

  • Members
  • Pip
  • 115 posts
  • Location:stuck in the middle of cyber space

Posted 17 May 2006 - 07:44 AM

View Postrc69, on May 17 2006, 05:44 AM, said:

Not to be picky or anything, but that actually means everything from start to finish is only [a-zA-Z]. Not just the first and last characters. Also, since you're using eregi, as opposed to ereg, you don't need the capital letters.

I'd love to offer some actual help, but i don't understand what you mean by "come in."

i mean, i a run that script i've got "Teks isn't valid". Coz that teks combine with charcter and number. I want only $teks contain with charcter can be "come in".
i'm sorry, my english very bad :D :D

thanx b4...

#5 HaloprO

    Requires Armed Escort

  • Members
  • PipPip
  • 310 posts
  • Gender:Male
  • Location:California, USA

Posted 19 May 2006 - 07:08 PM

Sorry rc69, that's what I meant to say - just came out all wrong :)
$pattern = "^come in$";
Try that :)

#6 joe

    Young Padawan

  • Members
  • Pip
  • 115 posts
  • Location:stuck in the middle of cyber space

Posted 25 May 2006 - 09:57 PM

thanks all, i've got the answer.....

thanx b4 :huh: :D





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users