Home > DeveloperSection > Forums > US Zip Code, auto format in mvc!
marcel ethan
marcel ethan

Total Post:105

Points:735
Posted on    March-09-2013 3:54 AM

 ASP.NET MVC ASP.NET MVC 
Ratings:


 1 Reply(s)
 2200  View(s)
Rate this:

Hi Expert!

I have one textbox in my MVC 4 project. In this textbox user entered zip code of US format. I want to auto set US format zip code during entered or after leave the textbox.


US format zip code as following

58595

Please help me!

Thanks in advance!



AVADHESH PATEL

Total Post:604

Points:4228
Posted on    March-09-2013 8:28 AM

Hi Marcel!

You could try following line of code

<script src="../../Scripts/jquery-1.7.1.min.js" type="text/javascript"></script>
<script src="../../Scripts/jquery.maskedinput.js" type="text/javascript"></script>
<script type="text/javascript">
    jQuery(function ($) {
         $("#zip").mask("99999");
    });
</script>

@Html.TextBox("zip", null)

Note:
"jquery-1.7.1.min.js" provided by MVC application
"jquery.maskedinput.js" you can download from following link

https://raw.github.com/digitalBush/jquery.maskedinput/1.3.1/dist/jquery.maskedinput.min.js


Don't want to miss updates? Please click the below button!

Follow MindStick