We have a system that requires users to input their ID into a field. User IDs are 6 digits long with leading 0's (when required).

For example: ID "789" is actually "000789"

Unfortunately, some users are not reading the instructions to include leading 0's, and we need a system to correct the input values when needed.

Our current solution is as follows:

``````%%[
VAR @input,@LENinput,@corrected
SET @input = QUERYPARAMETER("ID")
SET @LENinput = LENGTH(@input)

IF @LENinput == 1 THEN
SET @corrected = Concat("00000",@input)
ENDIF
IF @LENinput == 2 THEN
SET @corrected = Concat("0000",@input)
ENDIF
IF @LENinput == 3 THEN
SET @corrected = Concat("000",@input)
ENDIF
IF @LENinput == 4 THEN
SET @corrected = Concat("00",@input)
ENDIF
IF @LENinput == 5 THEN
SET @corrected = Concat("0",@input)
ENDIF
IF @LENinput == 6 THEN
SET @corrected = @input
ENDIF

/*Do things with @corrected input value*/
]%%
``````

In Excel, we would achieve this with :

``````=RIGHT("000000"&[ID], 6)
``````

We were able to solve with the following:

``````%%[
VAR @input,@inputmod,@corrected
SET @input = QUERYPARAMETER("ID")
SET @inputmod = concat("000000",@input)
]%%
``````

The Excel equivalent is:

``````=MID(A1,(LEN(A1)-6)+1, 6)
//Assuming Cell A1 is ="000000"&[ID]
``````

Trick way of doing a RIGHT() function in AMPScript!

• That really is a great solution! Thanks for sharing Mar 17 '17 at 13:16

Did you try:

``````var @input
set @input = FormatNumber(QueryParameter("ID"), "D6")
``````
• Your answer is phrased as a question. As such, it might have better been posted as a comment. If you believe this is the solution to the question, I suggest you rephrase to "I recommend trying:", doing, using, changing your code, etc. Mar 18 '17 at 17:33