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

an interesting question
Greetings folks, got to ask an interesting question...

let say
i have created a function s

Saving data from a form into a file
Hey everybody,

Sorry, I am really new to PHP coding and such but a project kind of got thrust

Insert data in Mysql and move to another page
I'm stuck with this simple problem. I need to insert data in Mysql and then hit submit and move to a

How do I replace any number of character occurences with one occurrence?
How do I replace any number of character occurences with one occurrence?

Let's say I have:

media recovery
Hi,
i startup the database i got the error

SQL> startup
ORACLE instance started.

Javascript form submit and radio buttons?
When this form is submitted, it is automatically resubmitted using JS.

All my fields are carr

SAP Logon Failed
I tried to login to SAP through MMC.

When i click start and give password.

it

pointer 102 question
I read a book
1
2
3
4
5
6
7
8
9
10
11
12
int main() {

Help pulling in 'id' with "read more" link
I'm trying to create snippets of my articles in the cms I'm creating, and then have them redirect to

Load Animated Image while cache is serve
I have a page that loads up using cache and took about 1 to 2 minutes before it loads to the page. <

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