Click here to Skip to main content
15,434,147 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi Team

im creating mvc asp.net form, i have model and view to do this for my email .But the problem my email textbox is not validating and have used data annotation from model side and view side i have this logic below. Please help me mates to resolve this issue.

What I have tried:

C#
<pre>   [Required]
        [EmailAddress]
        [Display(Name = "Email")]
        [RegularExpression(@"[a - z0 - 9._ % +-] +@[a-z0-9.-]+\.[a-z]{2,}$", ErrorMessage = "This field is required")]
        public string Email { get; set; }


<div class="row">
                    <label for"Email">Email:</label>
                    <div class="input-group col-md-4 col-md-offset-2 col-sm-2 col-xs-2">
                        <div class="input-group pull-right">
                                            
                            @Html.TextBoxFor(m => m.Email, new {@class = "form-control", type="email", placeholder = "example@example.com"})

                            <div class="input-group-append">
                                <div class="input-group-text">

                                </div>
                            </div>
                        </div>
                    </div>
                </div>
Posted
Updated 18-Mar-20 22:57pm

1 solution

Try getting rid of the spurious whitespace, escape the "reserv ed characters" and start your email with a "start of text" marker:
[a - z0 - 9._ % +-] +@[a-z0-9.-]+\.[a-z]{2,}$
Becomes
^[a-z0-9\._%+\-]+@[a-z0-9\.\-]+\.[a-z]{2,}$
 
Share this answer
 
Comments
gcogco10 19-Mar-20 5:03am    
@OriginalGriff i did and still not winning

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900