Jump to content

A little validation help please.


phpretard

Recommended Posts

I only want to allow letter and numbers and a space in between.

 

If there is a space after then I need to strip that but, that might be another issue.

 


<?php

$docName="Appraisal Agreement";

if (preg_match('/^[^a-z0-9-_ ]+$/i',$docName)){
echo "No Pass";
}else{echo "Passed";}

?>

 

 

Any help today?

 

 

Link to comment
Share on other sites

how about this, no regex

$docName="Ap%praisal Agreement";
$a = explode(" ",$docName);
if ( count($a) == 2){
print "ok, space in between\n";
}
if ( ctype_alnum ($a[0]) ){
print "$a[0] is alphanumeric\n";
}else{
print "$a[0] is not alphanumeric\n";
}

if ( ctype_alnum ($a[1]) ){
print "$a[1] is alphanumeric\n";
}else{
print "$a[1] is not alphanumeric\n";
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.