hosted by liquidweb


Go Back   Web Hosting Talk : Web Hosting Main Forums : Programming Discussion : how to display error if non english text?
Reply

Programming Discussion Discussions related to web programming languages and other related issues. Topics may include configuration, optimization, practical usage and database connectivity.
Forum Jump

how to display error if non english text?

Reply Post New Thread In Programming Discussion Subscription
 
Send news tip View All Posts Thread Tools Search this Thread Display Modes
  #1  
Old 03-08-2011, 12:02 AM
lexington lexington is offline
Disabled
 
Join Date: Dec 2003
Posts: 1,941

how to display error if non english text?


Some people are submitting text like arabic and other languages that use symbols into my post form. Is there a simple php code example that can detect anything other than regular english characters and display a message that only english text is allowed? Thanks.

Reply With Quote


Sponsored Links
  #2  
Old 03-08-2011, 11:37 AM
okapy okapy is offline
Newbie
 
Join Date: Aug 2002
Location: Ringwood, NJ
Posts: 14
if (preg_match("/[^\x00-\x7F]/",$string)) {
// Display Error
} else {
// English only
}

Reply With Quote
  #3  
Old 03-08-2011, 02:33 PM
lexington lexington is offline
Disabled
 
Join Date: Dec 2003
Posts: 1,941
Thanks, but it didn't work and I got the error message:

Quote:
Warning: preg_match() [function.preg-match]: No ending delimiter '/'
I used some text as an example that someone submitted into my form that reads:

Quote:
€егис‚€а†
Wouldn't the preg match just use letters A-Z and numbers as well as symbols !@#$%^ etc. to make this work?

*EDIT*

I finally found a google result but it doesn't really work either as it appears even for regular english text:

PHP Code:
 if ( !preg_match('/^[a-z0-9\p{P}]*$/i'$description) ) 
  {
       
$error_msg "Please only use English characters such as letters a - z and numbers 0 - 9.";
  } 
Perhaps it just needs to be tweaked?


Last edited by lexington; 03-08-2011 at 02:43 PM.
Reply With Quote
Sponsored Links
  #4  
Old 03-09-2011, 09:40 AM
Natcoweb Natcoweb is offline
WHT Addict
 
Join Date: Apr 2009
Posts: 170
if (! preg_match('/^[a-zA-Z0-9]+$/', $description)) {
...
}

__________________
█▌KVM-powered SSD VPS
▌Unmetered Dedicated Servers
▌Colocation at 100 Delawanna Ave, Clifton, NJ

Reply With Quote
  #5  
Old 03-09-2011, 12:33 PM
okapy okapy is offline
Newbie
 
Join Date: Aug 2002
Location: Ringwood, NJ
Posts: 14
Actually my way is better then [a-zA-Z0-9] because it keeps all punctuation as well, not just letters and numbers.

Your server set to differentiate quotes, so just change " to ' to fix the No ending delimiter '/' problem.

Here:

if (preg_match('/[^\x00-\x7F]/',$string)) {
// Display Error
} else {
// English only
}

Reply With Quote
  #6  
Old 03-10-2011, 05:03 PM
RincewindWizard RincewindWizard is offline
Junior Guru Wannabe
 
Join Date: Jul 2009
Location: London, UK
Posts: 47
Be very careful with this sort of regular expression. What's the purpose behind blocking these other characters? If you had a customer called Zo, would you allow her to enter her name? What's the actual problem you are experiencing?

__________________
Backup Machine - www.backupmachine.com
Automatically backup your website and databases with no software to install


Reply With Quote
Reply

Similar Threads
Thread Thread Starter Forum Replies Last Post
display password in clear text ryan14 Programming Discussion 14 02-18-2010 02:20 AM
Display code as Text revuelta Web Design and Content 3 11-29-2006 10:06 AM
Mouseover text to display image? vito Web Design and Content 4 08-31-2006 04:12 PM
need script code to display text in this way... hello20109876 Programming Discussion 3 05-05-2006 01:29 AM
Display text-Ads, using JavaScript mwaseem Programming Discussion 3 02-21-2006 09:33 AM

Related posts from TheWhir.com
Title Type Date Posted
Are you ready for Speed Networking at WHIR Events? Blog 2013-01-18 07:00:04
WHD.local 2013 London, UK Web Hosting Events 2012-11-20 15:34:40
Irish Web Host LetsHost Sending Billing Reminders to Customers via Text Message Web Hosting News 2012-03-13 17:00:48
Data Center Software Firm Rackwise Names Chief Financial Officer Web Hosting News 2012-02-06 12:54:41
WordPress, Tucows Among Sites Going Dark for SOPA and PIPA Protest Web Hosting News 2012-10-17 16:18:37


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes
Postbit Selector

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump
Login:
Log in with your username and password
Username:
Password:



Forgot Password?
Advertisement:
Web Hosting News:



 

X

Welcome to WebHostingTalk.com

Create your username to jump into the discussion!

WebHostingTalk.com is the largest, most influentual web hosting community on the Internet. Join us by filling in the form below.


(4 digit year)

Already a member?