Q:

mvc 4 custom format validator does not show error and allows the form to submit

I have the following validator for a MVC 4 view
    public class IpFormatValidator: ValidationAttribute 
    {
        protected override ValidationResult IsValid(object value, ValidationContext validationContext)
        {
            ValidationResult resp;

            if (value != null)
            {
                string ip ;
                IPAddress noUsed ;

                ip = value.ToString();

                if(IPAddress.TryParse(ip, out noUsed))
                {
                    resp = ValidationResult.Success;
                }
                else
                {
                    resp = new ValidationResult("Please enter a valid IP Address.");
                }
            }
            else
            {
                resp = new ValidationResult("" + validationContext.DisplayName + " is required");
            }

            return resp;
        }  

    }

And in the model I set it to the required field like this
    [IpFormatValidator]
    [Required]
    [Display(Name = "IP Address")]
    public String ipAddress { get { return nullOrTrim(this.ipAddressk__BackingField); } set { ipAddressk__BackingField = value.Trim(); } }

I have placed a breakpoint in the validator and I have seend that is being called and is returning the expected value but still the form does not show an error when an invalid IP address is typed.
While looking for an answer another post similar to this mention to include this at the end of the _Layout.cshtml
    @Scripts.Render("~/bundles/jquery")
    @Scripts.Render("~/bundles/jqueryval")
    @RenderSection("scripts", required: false)

A:

In order to get client side validation, your attribute must implement IClientValidatable and you must include a client side script that adds a method to the client side $.validator object.
This article THE COMPLETE GUIDE TO VALIDATION IN ASP.NET MVC 3 gives some good examples of how to implement it.
However from the comments, you can do this using the built-in RegularExpressionAttribute which will give you both server side and client side validation.
[RegularExpression("..your regex..",ErrorMessage = "Invalid IP Address")]
public String ipAddress { get; set; }

You can also create your own attribute based on RegularExpressionAttribute
namespace yourProject.Validation
{
  [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false)]
  public class IPAddressAttribute : RegularExpressionAttribute
  {
    public IPAddressAttribute() : base(@"..your regex..")
    {
        // Add default error message
        ErrorMessage = "Invalid IP Address";
    }
  }
}

And then register it in the global.asax.cs file
DataAnnotationsModelValidatorProvider.RegisterAdapter(typeof(IPAddressAttribute), typeof(RegularExpressionAttributeAdapter));

and use it as
[IPAddress]
public String ipAddress { get; set; }

