0

I want to start with alphabet in textbox. How can I check textbox is begining only alphabets ? For example:

  • N4534 -- True
  • NN435 -- True
  • 2N645 -- False
  • ?N645 -- False

Thanks

Bülent Alaçam
  • 187
  • 1
  • 1
  • 11

3 Answers3

10

try this

string str = "N4535";
bool isLetter = !String.IsNullOrEmpty(str) && Char.IsLetter(str[0]);
0
    string input = "N4534 ";

    Regex reg = new Regex("^[a-zA-z].*$"); 

    // Match the input and write results
    Match match = reg.Match(input);

    return match.Success;
Mudassir Hasan
  • 28,083
  • 20
  • 99
  • 133
0

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 += 
    }
}
RockWorld
  • 1,278
  • 2
  • 11
  • 24