how to test string whether it contains special characters
--------------------------------------------------------------------------------
please help dear experts on how to test string especially in username for example wheter it contains special charater and will return invalid ex for special characters (",',#,!,>,< ,?) except any letters for other languages ?
4 2791 Markus 6,050
Recognized Expert Expert
Try preg_match()
[php]
/*
- Using preg_match() we'll check for illegal characters:
*/
$_string = "lolzz#";
if(preg_match('/[^a-zA-Z0-9_-]+/', $_string))
# checks for anything BUT: a through z (upper and lower case) 0 - 9, underscore _ and hypen -
{
echo "String contained illegal characters";
}
else
{
echo "String was legal.";
}
[/php]
If you don't understand, then check out the php.net website.
Regards
how to test string whether it contains special characters
--------------------------------------------------------------------------------
please help dear experts on how to test string especially in username for example wheter it contains special charater and will return invalid ex for special characters (",',#,!,>,< ,?) except any letters for other languages ?
Just my curiosity: by 'foreign letters' do you mean Unicode (UTF-8) characters or just <255 characters?
Ronald
if i use preg_match or ereg to catch special characters it deal with other languages like arabic as sepecial characters how can i deal with that?
if i use preg_match or ereg to catch special characters it deal with other languages like arabic as sepecial characters how can i deal with that?
Now you are talking about Unicode characters. I.e. for arabic you would use an expression like (just an example)[php]$arabic=preg_ma tch('/[\x{600}-\x{6FF}]/u', $content)[/php]For searching Japanese circled numbers 1-9[php]preg_match('/[\x{2460}-\x{2468}]/u', $str);[/php]
I don't know enough of regular expressions and Unicode to say much more about it. So I hope someone schooled in Reg ex and Unicode can help you any further.
Ronald
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: lawrence |
last post by:
Someone on www.php.net suggested using a seems_utf8() method to test
text for UTF-8 character encoding but didn't specify how to write such
a method. Can anyone suggest a test that might work? Something that
maybe gives 90% confidence that a given block of text is or is not
UTF-8 encoded?
|
by: usgog |
last post by:
I need to implement a function to return True/false whether String A
contains String B. For example, String A = "This is a test"; String B =
"is is". So it will return TRUE if String A includes two "i" and two
"s". The function should also handle if String A and B have huge
values, like two big dictionary.
What's the best approach to achieve this with the best performance?
what's the Big O then?
I am thinking to put A and B into two...
|
by: Kamilche |
last post by:
I was looking for a way to speed up detecting invalid characters in my
TCP string, and thought of yet another use for the translate function!
If you were to 'translate out' the bad characters, and compare string
lengths afterwards, you would know whether or not the line contained
invalid characters. The new method is more than 10x faster than the
standard 'if char in string' test! So - here's the code plus sample
timings:
'''
Translate...
|
by: Mark |
last post by:
Hi,
My page has a table with many columns such that the right-side of the
table gets chopped off when printed. I specify a table width of 100%,
but otherwise no cell dimensions are specified. The culprits are 2 wide
columns which contain e-mail addresses.
I can get the page to fit entirely on the printer output if the browser
would break the e-mail address string at the '@' symbol. What I've done
for now is replaced the '@' in all...
|
by: Tom |
last post by:
Is there such a thing as a CONTAINS for a string variable in VB.NET? For
instance, I want to do something like the following:
If strTest Contains ("A","B", "C") Then
Debug.WriteLine("Found characters")
Else
Debug.WriteLine("Did NOT find characters!")
End If
| |
by: Shhnwz.a |
last post by:
Hi,
I am in confusion regarding jargons.
When it is technically correct to say.. String or Character Array.in c.
just give me your perspectives in this issue.
Thanx in Advance.
|
by: exoskeleton |
last post by:
please help dear experts on how to test string especially in username for example wheter it contains special charater and will return invalid!
please help...TIA
|
by: titan nyquist |
last post by:
How do you test a string to see if it contains special characters? I
want to ensure that any names typed into my form has only letters (and
maybe allow a dash and an apostrophe).
I can loop RealName.Contains("..."), but there must be a more elegant
solution.
|
by: Sobin Thomas |
last post by:
Hi All,
I want to pass a string that contains many special characters (: \ . _
etc) to another page in my website
through query string.
In my project I have a Gridview control ,in which there is a hyperlink
field.The Gridview 's datasource is set as a database table at runtime.The
hyperlink filed's DataNavigateUrlFields is set to "RecordID" ,which is a
field in my database table.The RecordID field contains many special
characters.I...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |