0

I have a Card Holder Name TextBox in MVC. I want to write Regular Expression for the same. So I want to allow UpperCase, space and numeric letters.

Name Format- "First Name" space "Last Name" e.g. JOHN METHEW10. "First Name" space "Middle Name" space "Last Name" e.g. CHRIS HENRY GAYLE

Space will be allowed only between words, not in other places.

I have written, But its not working properly.

[RegularExpression(@"([0-9A-Z]+[\s][0-9A-Z]+)", ErrorMessage="Invalid Card Holder Name")]
    public string NameOnCard
    {
        get
        {
            return m_strNameOnCard;
        }
        set
        {
            m_strNameOnCard = value;
        }
    }

I have modified the Regex.. not Im facing one issue, all is working fine. except one case. It should not allow multiple spaces between words.

4
  • 1
    You need to state what is wrong with your code. Is the regex not working properly? What if you just use ^[\w\s]{1,26}$ and try it against JOHN METHEW10? If it does not work, the problem is not with the regex. Jun 8, 2015 at 7:28
  • Its not working, that is why I have asked this question.
    – vivek jain
    Jun 8, 2015 at 8:35
  • See the following link and will find your required regx stackoverflow.com/questions/1559751/… Jun 8, 2015 at 8:46
  • "Its not working" does not describe the problem. Show some examples where it works OK and some more where it fails. Explain what it is doing correctly and what it is doing wrong.
    – AdrianHHH
    Jun 8, 2015 at 8:46

0

Your Answer

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

Browse other questions tagged or ask your own question.