Jump to content

[SOLVED] Validating a field - no invalid chars or spaces


JSHINER

Recommended Posts

are you saying you want to allow spaces in your usernames? currently, this check will only allow lower case and upper case letters. to allow spaces too it would be:

 

<?php

  if (!preg_match('/^[a-zA-Z ]$/',$data) {
    echo "FAIL - invalid username";
  }

?>

this will give small case, upper case letters and numbers only

 

<?php

  if (!preg_match('/^[a-zA-Z0-9]+$/',$data) {
    echo "FAIL - invalid username";
  }

?>

 

PS: added a + at the end to allow more than one charachters. i think you need that ?

this will give small case, upper case letters and numbers only

 

<?php

  if (!preg_match('/^[a-zA-Z0-9]+$/',$data) {
    echo "FAIL - invalid username";
  }

?>

 

PS: added a + at the end to allow more than one charachters. i think you need that ?

 

what they said....and you'll definitely need the plus...

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.