techpro Posted March 1, 2009 Share Posted March 1, 2009 I need a PHP function to return true or false depending on whether the supplied argument is in a valid format for a ham radio callsign. I think this should be possible using regular expressions but I can't figure out how to do it. A valid callsign would be a string containing, starting from the left: - zero or one digits, followed by - one or two alphabetics, then - one to four digits, then - one to three alphabetics. Is this possible? Quote Link to comment Share on other sites More sharing options...
phant0m Posted March 1, 2009 Share Posted March 1, 2009 That should do the trick: <?php function check_call_sign($callsign){ return preg_match('=\^d?[a-z]{1,2}\d{1,4}[a-z]{1,3}$=i', $callsign); } ?> Quote Link to comment Share on other sites More sharing options...
nrg_alpha Posted March 1, 2009 Share Posted March 1, 2009 Phant0m, I think you meant: '=^\d?[a-z]{1,2}\d{1,4}[a-z]{1,3}$=i' Switched the order of \ and ^ at the beginning. Quote Link to comment Share on other sites More sharing options...
techpro Posted March 2, 2009 Author Share Posted March 2, 2009 Thanks very much! That seems to work perfectly with all the examples I could think up. Well enough to keep the non-ham would-be spammers from registering anyway. Thanks again. Quote Link to comment Share on other sites More sharing options...
phant0m Posted March 2, 2009 Share Posted March 2, 2009 Oh yes, of course. Thanks for the correction. Should have tested it before posting Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.