Jump to content


Photo

php and mysql


  • Please log in to reply
2 replies to this topic

#1 michela

michela
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 20 October 2005 - 05:36 PM

if (!(strlen($_POST['student_id']) >= 6 && strlen($_POST['student_id']) <= 8)) {
error ('Student ID number is either too long or too short!\\n'.
'Please enter your 7 digit student ID number');

This is what I am using to make sure the user only inputs 7 numbers for their student id number, would anyone know how to make sure that it is exactly 7 numbers and not a space added in the middle?

Student id numbers are all like this - 1234567

I wish to avoid - 123 567

thanks

#2 effigy

effigy
  • Staff Alumni
  • Advanced Member
  • 3,600 posts
  • LocationIL

Posted 20 October 2005 - 07:37 PM

[!--PHP-Head--][div class=\'phptop\']PHP[/div][div class=\'phpmain\'][!--PHP-EHead--]if (preg_match(\'/^\d{7}$/\', $user_input)) {
  echo \'it is ok\';
}[/span][!--PHP-Foot--][/div][!--PHP-EFoot--]
Regexp | Unicode Article | Letter Database
/\A(e)?((1)?ff(?:(?:ig)?y)?|f(?:ig)?)\z/

#3 michela

michela
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 21 October 2005 - 03:26 PM

works perfect,
Thank YOU!!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users