473,396 Members | 2,061 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Acceptable characters are a-zA-Z0-9 and ; in php regex how can I do this?

Here is the scenario: I'm filtering the data being submitted by the user. Acceptable characters are a-zA-Z0-9 and semicolon(;) in php regex how can I do this?

Semicolon(;) serve as delimiter, so I'll be splitting the string into an array.

Please help.

Tenx!
Jul 9 '10 #1

✓ answered by dlite922

You basically did it. your class is [a-zA-Z0-9;]

For what you need it is

Expand|Select|Wrap|Line Numbers
  1.  
  2. if(preg_match('/^[a-z0-9;]+$/i',$foo))
  3. {
  4.    $data = explode(';',$foo); 
  5.   // it matches, do stuff
  6. }
  7.  
  8.  
Explanation: From beginning of the string (^) to end ($), ensure there are one more of the following characters a-z, and numbers 0-9 in any order, case Insensitive (i).

Cheers,

Dan

2 1795
dlite922
1,584 Expert 1GB
You basically did it. your class is [a-zA-Z0-9;]

For what you need it is

Expand|Select|Wrap|Line Numbers
  1.  
  2. if(preg_match('/^[a-z0-9;]+$/i',$foo))
  3. {
  4.    $data = explode(';',$foo); 
  5.   // it matches, do stuff
  6. }
  7.  
  8.  
Explanation: From beginning of the string (^) to end ($), ensure there are one more of the following characters a-z, and numbers 0-9 in any order, case Insensitive (i).

Cheers,

Dan
Jul 9 '10 #2
Now its working using your code. The + sign before the $ sign is what I omitted in my code. So I have decided to post it here for an immediate solution.

Thanks friend, you're the man.
Jul 9 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

17
by: Behrang Dadsetan | last post by:
Hi all, I would like deleting specific characters from a string. As an example, I would like to delete all of the '@' '&' in the string 'You are ben@orange?enter&your&code' so that it becomes...
11
by: Marian Aldenhövel | last post by:
Hi, I am very new to Python and have run into the following problem. If I do something like dir = os.listdir(somepath) for d in dir: print d The program fails for filenames that contain...
43
by: Vladimir | last post by:
Method UnicodeEncoding.GetMaxByteCount(charCount) returns charCount * 2. Method UTF8Encoding.GetMaxByteCount(charCount) returns charCount * 4. But why that? Look: /* Each Unicode character...
11
by: santosh | last post by:
Hi, A book that I'm currently using notes that the fgets() function does not return until Return is pressed or an EOF or other error is encountered. It then at most (in the absence of...
2
by: Satya | last post by:
Hi I have a field called method, which has values like App,BCC,DED using the below function im trying to delimit with ":", so the values should be like "App","BCC","DED" but the...
4
by: randy1200 | last post by:
Using Visual Studio 2005. I'm using XmlReader to read data into a string variable in C#. Works great! Every once in a while, I see that the string data contains a symbol that looks like a...
0
by: CodeMan007 | last post by:
Hi , I have a small application built using the JSP/Bean model and using MS Access as database. I have a page where the user can enter the errors and exceptions that the user is facing and submit...
8
by: Wayne Shu | last post by:
Why there has such a rule for the template non-type argument?? but address of an object of external linkage is acceptable!! e.g. template <int *p> class C; int i; int arr;
4
by: none | last post by:
I have an ASP.NET application, hosted on two web servers. I am looking for advice on what should be an acceptable level of page faults on these production servers. If the acceptable level is zero,...
13
by: Liang Chen | last post by:
Hope you all had a nice weekend. I have a question that I hope someone can help me out. I want to run a Python program that uses Tkinter for the user interface (GUI). The program allows me to type...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.