1

I want to validate textbox is it only text. But I need some special chars for Eastern Europe such as

č,ć,š,đ,Č,Ć,Š,Đ,ž,Ž (ASCII is for e.g: & #269;)

I have this validation which is just fine but it not supports my special chars:

 [RegularExpression(@"^[a-zA-Z]+$", ErrorMessage = "Use letters only please")]

I've tried to add like this but I failed:

 [RegularExpression(@"^[a-zA-Z]+$&#269", ErrorMessage = "Use letters only please")]

If you know way around I would appreciate it.

3
  • 1
    Why put them outside the character class? Use [RegularExpression(@"^[a-zA-Z\u010D]+$", ErrorMessage = "Use letters only please")] or use literals: [RegularExpression(@"^[a-zA-ZčćšđČĆŠĐžŽ]+$", ErrorMessage = "Use letters only please")] Commented Feb 2, 2016 at 21:35
  • Thanks! It didnt across on my mind. Commented Feb 2, 2016 at 21:50
  • Will you delete the question or shall I post an answer? Commented Feb 2, 2016 at 21:52

1 Answer 1

2

You should put them inside the character class.

Use something like (and add hex values with \u notation):

[RegularExpression(@"^[a-zA-Z\u010D]+$", ErrorMessage = "Use letters only please")]

or use literals (easier and more maintainable):

[RegularExpression(@"^[a-zA-ZčćšđČĆŠĐžŽ]+$", ErrorMessage = "Use letters only please")]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.