sloth456 Posted June 1, 2009 Share Posted June 1, 2009 Hi I have a form where users are required to enter their Liberty reserve account number (liberty reserve is a payment processor) An account number always starts with the letter "U" followed by 7 digits. So an example would be U2581606 How can I check that a user has inputted a number in this exact format? Link to comment https://forums.phpfreaks.com/topic/160489-solved-validate-a-liberty-reserve-number/ Share on other sites More sharing options...
Ken2k7 Posted June 1, 2009 Share Posted June 1, 2009 <?php $str = 'U2581606'; if (preg_match('#U\d{7}#', $str)) echo 'valid liberty reserve number'; Link to comment https://forums.phpfreaks.com/topic/160489-solved-validate-a-liberty-reserve-number/#findComment-846923 Share on other sites More sharing options...
nrg_alpha Posted June 1, 2009 Share Posted June 1, 2009 If the form has it's own Liberty reserve account number field, You have a few choices; a) ensure that that field has a limited set of allowable characters, -or- b) Have no restrictions, and upon processing the variable, strip that variable of all spaces (in the event the user inserts say a space between U and the numbers for example - perhaps for formatting purposes, much like some people do when filling out credit card numbers.. or maybe even strip out all non alphanumerics altogether in the event of say a dash insertion), then based off of Ken's pattern, do something like this: #^U\d{7}$# or #^U[0-9]{7}$# for extra assurance... Link to comment https://forums.phpfreaks.com/topic/160489-solved-validate-a-liberty-reserve-number/#findComment-847078 Share on other sites More sharing options...
sloth456 Posted June 3, 2009 Author Share Posted June 3, 2009 Thanks guys. Link to comment https://forums.phpfreaks.com/topic/160489-solved-validate-a-liberty-reserve-number/#findComment-848469 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.