Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

String Length

Status
Not open for further replies.

Brianfree

Programmer
Feb 6, 2008
220
GB
Hi, how do i convert a string with less than 5 chars to a string that has 5 chars with leading zeros?

ie

1234 converts to 01234
300 converts to 00300
12 converts to 00012
51284 stays the same

Etc.

Many thanks,

Brian
 
Cool!!! Many thanks!!

I am also trying to validate numberplates i.e

BN06OBE

How can i check if they are valid numberplates or not (as in correct format)?

Many thanks,

Brian
 
Hi

Not sure how British numberplates are formatted, but I would definitely use a regular expression. Based on your example :
Code:
if ([url=http://php.net/preg-match/]preg_match[/url]('/^[[:alpha:]]{2}[[:digit:]]{2}[[:alpha:]]{3}$/',$string)) echo 'OK';

Feherke.
 
There are a number of formats for britch number plated depending on the age of the car

examples are:

X123ABC
ABC123X
AB09ABC

& realy early examples are either 1-3 numbers followed by 1-3 letters or 1-3 letters followed by 1-3 numbers (I think)

I believe that totaly custome priovate plates are also possible if you have enough £
 
Yes, a 1 might stand in for I , or zero for O e.g.
J0HN (might not actualy be avaiable but you get the picture)
You could look on the DVLA (Driver Vehicle Licensing Authrority) at might have some usefull stuff.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top