Adding space between numbers

For integers use function numberWithSpaces(x) { return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ” “); } For floating point numbers you can use function numberWithSpaces(x) { var parts = x.toString().split(“.”); parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ” “); return parts.join(“.”); } This is a simple regex work. https://developer.mozilla.org/en-US/docs/JavaScript/Guide/Regular_Expressions << Find more about Regex here. If you are not sure about whether the number … Read more

Add padding to HTML text input field

You can provide padding to an input like this: HTML: <input type=text id=firstname /> CSS: input { width: 250px; padding: 5px; } however I would also add: input { width: 250px; padding: 5px; -webkit-box-sizing: border-box; /* Safari/Chrome, other WebKit */ -moz-box-sizing: border-box; /* Firefox, other Gecko */ box-sizing: border-box; /* Opera/IE 8+ */ } Box … Read more

Aligning text and select boxes to the same width in CSS?

This is because the <input type=”text” /> element has a slightly different default style to the <select> element e.g. the border, padding and margin values may be different. You can observe these default styles through an element inspector such as Firebug for Firefox or the built-in one for Chrome. Futhermore, these default stylesheets differ from … Read more

Set the caret/cursor position to the end of the string value WPF textbox

You can set the caret position using CaretIndex property of a TextBox. Please bear in mind that this is not a DependencyProperty. Nevertheless, you may still set it in XAML like this: <TextBox Text=”123″ CaretIndex=”{x:Static System:Int32.MaxValue}” /> Please remember to set CaretIndex after Text property or else it will not work. Thus it probably won’t … Read more

Specifying maxlength for multiline textbox

Use a regular expression validator instead. This will work on the client side using JavaScript, but also when JavaScript is disabled (as the length check will be performed on the server as well). The following example checks that the entered value is between 0 and 100 characters long: <asp:RegularExpressionValidator runat=”server” ID=”valInput” ControlToValidate=”txtInput” ValidationExpression=”^[\s\S]{0,100}$” ErrorMessage=”Please enter … Read more