Reputation: 260
I work with symfony framework and I have an input field in a form called 'PostalCode' that is a integer type, I like that is accept the number 0 in the begin of the number because for exemple 01256 ? there are any solution to do that ? thanks for all your answers
Upvotes: 0
Views: 1196
Reputation: 116110
An integer is a numeric value, without representational formatting. This means that leading zero's are gone, as well as thousands-separators.
You may explicitly add formatting again when displaying your value, but it is not stored as part of the integer. For that reason, an integer input field will allow numeric input, but will typically discard such formatting information.
So, if you want people to input leading zeroes, make it a string field so they can type anything. You may provide additional rules for your input validation (for instance a regular expression that must be matched) to encourage people to type valid input instead of just some random characters.
Upvotes: 3
Reputation: 1153
You can use a regex expression to check the format of your PostalCode and allow a 0 in the first position like this : #^[0-9]{5]$#
Hope it will help you.
Upvotes: 0