Reply
Script to check a string for certain numbers
Old 05-01-2007, 04:49 AM Script to check a string for certain numbers
cbeaudin's Avatar
Super Talker

Posts: 126
Name: Clayton Beaudin
Location: Proud to be Canadian
Im looking for the best way to do the following, i tried myself but its over my head.

Users will enter a letter/number string into a form like the one below:
G11223344556677

I need a script to check that the first character is a letter, the rest of the characters are numbers and that the string is 15 characters long.

Furthermore, i need to seperate the last 6 numbers into variables in sets of two. the result should look like:
PHP Code:
$lastset==77;
$middleser==66;
$firstset==55
I should be able to figure out the rest myself hopefully . Thanks for all your help much appreciated.
cbeaudin is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
Old 05-01-2007, 05:00 AM Re: Script to check a string for certain numbers
kaisellgren's Avatar
Extreme Talker

Posts: 214
Name: Kai Sellgren
Location: Finland
Okay. I'm very tired right now, but I'll try to help.

PHP Code:
<?php
$string 
'G11223344556677';
if (
preg_match('/\w\d{14}/i',$string))
 {
  
$a1 substr($string,-2,2);
  
$a2 substr($string,-4,2);
  
$a3 substr($string,-6,2);
  echo 
$a1.$a2.$a3;
 }
else
 echo 
'**** seem to be wrong string';
?>
__________________
Adept Web Community
kaisellgren is offline
Reply With Quote
View Public Profile Visit kaisellgren's homepage!
 
Old 05-01-2007, 05:23 AM Re: Script to check a string for certain numbers
cbeaudin's Avatar
Super Talker

Posts: 126
Name: Clayton Beaudin
Location: Proud to be Canadian
Thanks very much. Works great.
cbeaudin is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Script to check a string for certain numbers
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.11026 seconds with 12 queries