0

How to code NAME textbox that accepts only letters & blankspaces. Same for NUMBER textbox:

private void tbOwnerName_TextChanged(object sender, EventArgs e) { /*if (!char.IsControl(e.KeyChar) && !char.IsLetter(e.KeyChar)) { e.Handled = true; base.OnKeyPress(e); MessageBox.Show("Please enter Characters only"); }*/ } 
2

1 Answer 1

2

The proper way to do that is using regular expressions , in C# you can use REGEX class to check if an string matches a patterns that declared by regular expression.

Regex regex = new Regex(@"^[a-zA-Z0-9_ ]*$"); Match match = regex.Match("Dot 55 Perls"); if (match.Success) { //do something } 

this answer might help you to find the proper regular expression for your situation.

Sign up to request clarification or add additional context in comments.

2 Comments

Better to add some sample code, otherwise it will be considered as a low quality answer.
I know that but i posted answer from my smart phone , and it was hard to add sample code

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.