ctype() validation - allowing illegal characters


Posted on 16th Feb 2014 07:03 pm by admin

Hello,
I use ctype() to filter and validate a user form. However, I am trying to allow certain characters.

Example:

Code: [Select]//Validate Copay
$allow = array('$', '.');

if (!empty($copay) && strlen($copay) < 6 || strlen($copay) > 8) { // IF copay is not empty and not between 6 and 8 characters
$error .= 'COPAY has a maximum of 8 characters. An example of a maximum $0000.00, and a minimum $00.00.<br />';
$output_form = true;
}

if (!empty($copay) && !ctype_digit(str_replace($allow), '', $copay)) { // IF copay is not empty and contains illegal characters (Allow $ and .)
$error .= 'COPAY contains illegal characters.<br />';
$output_form = true;
}
With this example, my test comes back containing illegal characters. I've tried changing it here and there, but get the same results. Thank you!

No comments posted yet

Your Answer:

Login to answer
308 Like 50 Dislike
Previous forums Next forums
Other forums

Any Good MMORPGs you've played?
I'm about to have ALOT of free time on my hands (finished highschool) and I need something to fill t

PHP hyperlinks generator
Hi

I need some help to get this done using php:


1 - I have few hyperlinks say 500

Get value from Select menu
Hi!

Have tried to find the solution on the web. Don't know if there is an easy one. A descrip

extract a file from zip file
hi,
i know how to unzip a zip file in php, but is there a way to just extract a certain file only

php title problem
Hi,

I am having a problem managing my page title with PHP.

Currently I have my <

$variable $variables type question
I need to be able to designate an array element dynamically, so I thought to use a variable variable

Progress bar tracking file downloads
Hey guys, was wondering if there was a way to track how far a file has been downloaded. I know there

SOAP Issue
Hi,

I am facing some understanding problem with SOAP basic.kindly recommend some SOAP expert.

Multithreading design
Hi

I have come up with a Singleton class that manages a pool of database connections. Basical

How can I Compare two xml documents?
Hi all,

I am doing a POC for my project and I am using XE database 10g version.

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash