Regular Expression not disappearing

Posted by user2439019 on Stack Overflow See other posts from Stack Overflow or by user2439019
Published on 2013-11-08T03:50:44Z Indexed on 2013/11/08 3:53 UTC
Read the original article Hit count: 133

Filed under:

I have 3 phone fields and any one is required. SO i had a custom validation class to make any one of them is required. And i am calling those class as follows

[RegularExpression(@"^\(?([0-9]{3})\)?. ]?([0-9]{3})[-. ]?([0-9]{4})$", ErrorMessage = "Entered phone format is not valid. <br/> 10 digits are required.<br/> No spaces between digits. <br/> Numbers only.")]
[AtLeastOneRequired("PhoneHome", "PhoneMobile", "PhoneOffice", ErrorMessage = "Please     provide either of PhoneHome or PhoneMobile or phoneOffice. ")]
public string PhoneHome { get; set; }

[StringLength(11, MinimumLength = 10)]
[RegularExpression(@"^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$", ErrorMessage = "Entered phone format is not valid. <br/> 10 digits are required.<br/> No spaces between digits. <br/> Numbers only.")]
[Display(Name = "Prompt_PhoneOffice", ResourceType = typeof(ResContactItems))]
public string PhoneOffice { get; set; }

[StringLength(11, MinimumLength = 10)] 
[RegularExpression(@"^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$", ErrorMessage   = "Entered phone format is not valid. <br/> 10 digits are required.<br/> No spaces between digits. <br/> Numbers only.")]
[Display(Name = "Prompt_PhoneMobile", ResourceType = typeof(ResContactItems))]
public string PhoneMobile { get; set; }

The problem is with only "PhoneHome " field , if i enter incorrect format, it will display error message based ont he regular expression given .But the regular expression message is not disappearing wwhen we enter the correct format too.It will disappear only in f the field is empty.Other two fields are showing properly. Is this due to the custom class i am calling.?

Please help me to sort out this issue

Thanks,

Vidya

© Stack Overflow or respective owner

Related posts about nsregularexpression