Reputation: 197
I want to start with alphabet in textbox. How can I check textbox is begining only alphabets ? For example:
Thanks
Upvotes: 0
Views: 386
Reputation: 1288
1> Create a behaviour as shown here
2> Subscribe to TextChanged event.
3> Apply RegEx (E.g. "^[a-zA-z].*$")
4> clear text if RegEx return false.
<TextBox Text="{Binding ...}" >
<e:Interaction.Behaviors>
<b:AlphaTextBehavior/>
</e:Interaction.Behaviors>
</TextBox>
public class DragBehavior : Behavior<TextBox>
{
protected override void OnAttached()
{
// AssociatedObject.TextChanged +=
}
}
Upvotes: 0
Reputation: 28771
string input = "N4534 ";
Regex reg = new Regex("^[a-zA-z].*$");
// Match the input and write results
Match match = reg.Match(input);
return match.Success;
Upvotes: 0
Reputation: 966
try this
string str = "N4535";
bool isLetter = !String.IsNullOrEmpty(str) && Char.IsLetter(str[0]);
Upvotes: 10