Reply
Regular Expression question ...
Old 11-11-2004, 01:05 AM Regular Expression question ...
foobar's Avatar
Extreme Talker

Posts: 225
I'm writing a script that takes a submitted form and adds it to the database. Before doing so however, the script verifies certain fields and checks to make sure that they are ok before adding them.

In the case of one field, I check to make sure that it has only numeric characters. So, I use a regular expression that checks for non-digit characters. Here's the code ...

PHP Code:
if (ereg("\D"$values['thread']))

  
$msgs[] = "The Thread ID must hold numeric values only.<br />"
  
$values['thread'] = "";

Problem is: it doesn't work. It always says that there are non-digit characters, even when I enter only numbers. The field has a max size of 5, and even if I enter 5 numbers, it's incorrect.

Can someone help me out here? Thanks.
foobar is offline
Reply With Quote
View Public Profile Visit foobar's homepage!
 
When You Register, These Ads Go Away!
Old 11-11-2004, 01:08 AM
foobar's Avatar
Extreme Talker

Posts: 225
Never mind guys, I found it. I though \D was supposed to be a shortcut for non-digit. It doesn't work. I replaced \D with [^0-9] and it works now. Pretty dumb if you ask me ...

(Sorry for the double post ...)

Last edited by foobar : 11-11-2004 at 01:11 AM.
foobar is offline
Reply With Quote
View Public Profile Visit foobar's homepage!
 
Old 11-11-2004, 02:36 PM
Junior Talker

Posts: 2
Hi


You can use (\d) if you use the Perl Compatible Style regex functions (preg_). They are more resource friendly too!



F!
Fataqui is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Regular Expression question ...
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.11760 seconds with 12 queries