Solved

regular expression question in php preg_match

Posted on 2008-06-16
1
174 Views
Last Modified: 2012-05-05
i'd like to check the following

okay:
'-'
'-1'
'-1212'
'-12.22'

not okay:
'- '
'#'
'-1/1'
'-1,2'
'-1.2.2.2'
'1,2'
'1/1'
'1.2.2'

Thanks
0
Comment
Question by:edyonline
1 Comment
 
LVL 49

Accepted Solution

by:
Roonaan earned 125 total points
Comment Utility
if(preg_match('/^\-\d+(\.\d+)?$/', $value)) {
  //valid
} else {
  //invalid
}
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now