Getting Started with ASP.NET MVC - Part 5: How to do programming with razor syntax
First Time? You can support us by signing up. It takes only 5 seconds. Click here to sign up. If you already have an account, click here to login.


Upload Image Close it
Select File

I am Jalpesh Vadgama a Microsoft MVP for Visual C# and BrainBench Certified ASP.NET Developer having more then 6 years of experience in .NET Technology.
Browse by Tags · View All
#ASP.NET 88
#DOTNET 87
BRH 79
ASP.NET 72
#.NET 52
C#.NET 48
ASP.NET 4.0 31
ASP.NET MVC 29
VisualStudio 27
VisualStudio2010 26

Archive · View All
December 2010 16
July 2011 13
April 2011 13
April 2012 12
January 2011 12
June 2011 11
May 2011 11
August 2011 7
August 2010 7
January 2012 6

Email-New Html5 input element

Jan 29 2012 2:50PM by Jalpesh   

In most of the websites we have contact forms and other forms where we have some standard inputs like Phone,Email and Website URL and those are widely used in any site and has specific features. Email is one of the most standard used input elements which are used in our forms. Till HTML 4.1 we have standard input type text and that’s for we were doing input validation with java script and other technologies. While we all know HTML5 is there and it’s contains lots of goodies, One of them is email input types.

Email input type comes with HTML5 as standard input type. It has all validation by default which are required for email input like we must have @ and . while we entered email input type.

Let’s check email input type in details. Let’s create a ASP.NET MVC3 project with HTML5 Markup like following. To do that I have created a new Project called via File->New Project-> ASP.NET MVC 3 web application like following.

HTML5, Email,Input Element

Once you click ok following dialog box will come. Where you can select HTML5 markup as default.

HTML5Markup

Here I have selected HTML “Use hTML5 semantic markup”. So It will create a new project with HTML5 semantic markup. Now our Basic ASP.NET MVC application is ready so let’s write some code to check how Email input works. So I have written following code to check how its works in Index view of ASP.NET MVC application.

Following is a code for that.

@{
   ViewBag.Title = "Home Page";
}

<h2>@ViewBag.Message</h2>
<p>
   To learn more about ASP.NET MVC visit <a href="http://asp.net/mvc" title="ASP.NET MVC Website">http://asp.net/mvc</a>.
</p>
<form action="" method="post">  
       <label for="emailInput">Email:</label>  
       <input id="emailInput" name="emailInput" type="email" />  
 
       <button type="submit"> Check Input email</button>  
</form> 

Now let’s run that in browser. It will look like following.

Email, Input Type, Validation,HTML5

Now I am trying to input wrong email address and when I press submit button. It will show validation like following.

Email Input Type

So it’s showing validation that please input valid email address. Here I have not written any code for validation. So It’s a by default browser functionality. For the browsers which don’t understand email input type it will work as same old input type. That’s it. It's very easy and with the help of HTML5 we can do lots of other stuff. I am going to explain them in future posts. Hope you like it. Stay tuned for more..Happy programming.

Shout it

Tags: ASP.NET, DOTNET, HTML5, HTML Tip,


Jalpesh
14 · 13% · 2873
0
Liked
 
0
Lifesaver
 
0
Refreshed
 
0
Learned
 
0
Incorrect



Submit

1  Comments  

  • Does it handle + signs in the validation?

    commented on Feb 6 2012 12:41AM  .  Report Abuse This post is not formatted correctly
    NoahK
    2165 · 0% · 3

Your Comment


Sign Up or Login to post a comment.

    Copyright © Beyondrelational.com Contact us      Privacy Policy      Terms of use      Report Abuse      Advertising