Textbox Validation
-
Hello, I would like to ask if how do allow 2 input only in a textbox after entering decimal.
-
Hello, I would like to ask if how do allow 2 input only in a textbox after entering decimal.
use regular expression validator and in the validation expression specify this: (^\d*\.\d{2}$)
Manas Bhardwaj Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
-
use regular expression validator and in the validation expression specify this: (^\d*\.\d{2}$)
Manas Bhardwaj Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
Hello, Would you mine if could you give me some sample of using the format validation I have tried using lastindexof but my code doesn't work unless if I enter "." at begginning of my textbox. my code is this
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles _
TextBox1.TextChangedIf TextBox1.Text.IndexOf(".") Then TextBox1.MaxLength = Val(TextBox1.TextLength) + 2 End If
End Sub
Thanks, dfan23
-
Hello, Would you mine if could you give me some sample of using the format validation I have tried using lastindexof but my code doesn't work unless if I enter "." at begginning of my textbox. my code is this
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles _
TextBox1.TextChangedIf TextBox1.Text.IndexOf(".") Then TextBox1.MaxLength = Val(TextBox1.TextLength) + 2 End If
End Sub
Thanks, dfan23
He's already given you the regular expression you need to use. Why haven't you used that? The code you've got here isn't validation, it's input constraint - which is a different thing altogether. What happens if you put in .AA (hint - your code thinks it's valid, but it patently is wrong)?
"WPF has many lovers. It's a veritable porn star!" - Josh Smith
As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
-
He's already given you the regular expression you need to use. Why haven't you used that? The code you've got here isn't validation, it's input constraint - which is a different thing altogether. What happens if you put in .AA (hint - your code thinks it's valid, but it patently is wrong)?
"WPF has many lovers. It's a veritable porn star!" - Josh Smith
As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
Hello, Can I ask again if there would there would be other way. I would like to ask also doesn't that the regular expression check if the input in textbox is as what the expression use? Thanks, dfan23
-
Hello, Can I ask again if there would there would be other way. I would like to ask also doesn't that the regular expression check if the input in textbox is as what the expression use? Thanks, dfan23
I don't believe on restricting user for inputting. rather i will do it as following. This code will accept user decimal input and after user looses focus of this text box the validation logic will do the stuff for you.
private void textBox1\_Validating(object sender, CancelEventArgs e) { decimal result = 0.00M; decimal.TryParse(textBox1.Text, out result); textBox1.Text = decimal.Round(result, 2).ToString(); }
Let me know if you like this.
wrote:
Knock out 't' from can't, You can if you think you can :cool:
-
Hello, Can I ask again if there would there would be other way. I would like to ask also doesn't that the regular expression check if the input in textbox is as what the expression use? Thanks, dfan23
If you don't want to use a regular expression check, you could always use a masked edit box and set it to restrict the input.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith
As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.