Reputation: 33
I have a field that has a length of 6 and takes in 5 or 6 digit codes.
If a 5 digit code is entered, there needs to be a space in front of the first digit.
Currently I have the text aligned to the right which helps, but is there a way to have any leftover bytes automatically filled with a space?
Upvotes: 0
Views: 42
Reputation: 1968
Bind a Javascript event on the onblur event, then modify the content of the TextBox from there.
<asp:TextBox ID="textbox1" ClientIDMode="Static" runat="server" onblur="CheckLength()" />
Then JS side :
function CheckLength() {
var val = document.getElementById('textbox1').value;
if (val.length == 5) {
document.getElementById('textbox1').value = " " + val;
}
}
[EDIT] If the idea is mainly to show the user that there is a space in front, then instead of changing the value, add a CSS class that will make visual modifications to the textbox (padding-left, textBox background, ...)
Upvotes: 1