Skip to content

Instantly share code, notes, and snippets.

@cleytonferrari
Created February 5, 2013 21:53
Show Gist options
  • Save cleytonferrari/4718095 to your computer and use it in GitHub Desktop.
Save cleytonferrari/4718095 to your computer and use it in GitHub Desktop.
Código do post em meu blog
bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
"~/Scripts/jquery.unobtrusive*",
"~/Scripts/jquery.validate*",
"~/Scripts/methods_pt.js"));
PM> Install-Package Microsoft.AspNet.Mvc.pt-br
@model ValidandoDataeMoeda.Models.Produto
@{
ViewBag.Title = "Index";
}
<h2>Validando Data e Moeda em ASP.Net MVC 4</h2>
@using (Html.BeginForm()) {
@Html.ValidationSummary(true)
<fieldset>
<legend>Produto</legend>
<div class="editor-label">
@Html.LabelFor(model => model.Nome)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Nome)
@Html.ValidationMessageFor(model => model.Nome)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Validade)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Validade)
@Html.ValidationMessageFor(model => model.Validade)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Valor)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Valor)
@Html.ValidationMessageFor(model => model.Valor)
</div>
<p>
<input type="submit" value="Create" />
</p>
</fieldset>
}
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}
using System.Web.Mvc;
using ValidandoDataeMoeda.Models;
namespace ValidandoDataeMoeda.Controllers
{
public class HomeController : Controller
{
public ActionResult Index()
{
return View();
}
[HttpPost]
public ActionResult Index(Produto produto)
{
return View(produto);
}
}
}
/*
* Localized default methods for the jQuery validation plugin.
* Locale: PT_BR
*/
jQuery.extend(jQuery.validator.methods, {
date: function (value, element) {
return this.optional(element) || /^\d\d?\/\d\d?\/\d\d\d?\d?$/.test(value);
},
number: function (value, element) {
return this.optional(element) || /^-?(?:\d+|\d{1,3}(?:\.\d{3})+)(?:,\d+)?$/.test(value);
}
});
public class Produto
{
public string Nome { get; set; }
public DateTime Validade { get; set; }
public decimal Valor { get; set; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment