validation

Custom Validator and specifying type of message

I have a custom validation in the enterprise validation block. The DoValidate method is as shown below. protected override void DoValidate(Double objectToValidate, object currentTarget, string key, ValidationResults validationResults) { if (!IsSalMoreThanMinWage(objectToValidate)) { //Here I need to mark this messa...

A specific Phone Number RegEX

Greetings, I need to implement a jquery based validation for a text field that contains a phone number, for that I need the regular expression of these two strings, I am requesting this because I am very naive with RegEx: First One: 0(5NN) NNN NN NN Second One: 0(53N) NNN NN NN N means an integer between 0-9 ...

UpdateModel() fails after migration from MVC 1.0 to MVC 2.0

We are in the process of migrating our ASP.NET MVC 1.0 web app to MVC 2.0 but we have run into a small snag. In our report creation wizard, it is possible leave the Title text box empty and have it be populated with a generic title (in the post action). The code that does the update on the model of the Title is: if (TryUp...

Stop the user entering ' char

I have a search page where I would like to stop the user entering a ' into textboxes, or replace it with a suitable character. Can anyone help me achieve this in asp.net vb ? For example if a user searches for O'Reilly the search crashes with error: Line 1: Incorrect syntax near 'Reilly'. Unclosed quotation mark before the character ...

How can I validate the result in an ASP.NET MVC editor template?

I have created an editor template for representing selecting from a dynamic dropdown list and it works as it should except for validation, which I have been unable to figure out. If the model has the [Required] attribute set, I want that to invalidate if the default option is selected. The view model object that must be represented as t...

How to validate the maximum allowed number of characters in a multiline asp:TextBox?

I have an asp:TextBox and I want to validate that the number of characters typed in by the user is not more than 250 characters. Because it's a multiline TextBox the MaxLength property does not work. At the moment I only see the option to use a CustomValidator with checking TextBox1.Text.Length on server side and perhaps in addition som...

Retrieve Table Row Index of Current Row

Hi Everyone, I am trying to validate a text input when it loses focus. I would like to know which row of the table it is in. This is what I have so far and it keeps coming back as undefined. Any ideas? $("div#step-2 fieldset table tbody tr td input").blur(function() { var tableRow = $(this).parent().parent(); if ($.trim($(th...

When using Data Annotations with MVC, Pro and Cons of using an interface vs. a MetadataType

If you read this article on Validation with the Data Annotation Validators, it shows that you can use the MetadataType attribute to add validation attributes to properties on partial classes. You use this when working with ORMs like LINQ to SQL, Entity Framework, or Subsonic. Then you can use the "automagic" client and server side vali...

jQuery Validation plugin results in empty AJAX POST

Hi, I have tried to solve this issue for at couple of days with no luck. I have a form, where I use the validation plugin, and when I try to submit it, it submits empty vars. Now, if I remove the validation, everything works fine. Here is my implementation: $(document).ready(function(){ $("#myForm").validate({ rules: { field1: {...

error_messages_for and redirect

I know, if i will write "redirect_to" instead of "render :action", i'll lose my @object's errors. My code: def play @room = params[:id][0,1] @current_players = CurrentPlayer.all(:conditions => {:room => @room}) end def join @new_player = CurrentPlayer.new(:user_id => current_user.id, :team_id => nil, :room => params...

recaptcha asp.net always returns invalid

The reCaptcha example for ASP.NET does not seem to work. I followed the instructions but it always returns false, "The verification words are incorrect.". The entries are good. I'm using localhost as the site but am not getting any public/private key errors which I did get when adding a bad key (as a test). I've seen this error report...

How to enforce unique-field validation in MVC

I am in the way building some MVC Application and I really love the Data Annotations support in MVC. The build in support is good enough to enforce simple validation checkup. I wonder, how to implement unique-field validation using custom data-annotation ? For example, I have a view model that need the user to register a new login name, ...

Regular expression to validate whether the data contains numeric ( or empty is also valid)

Hi all, i have to validate the data contains numeric or not and if it is not numeric return 0 and if it is numeric or empty return 1. Below is my query i tried in SQL. SELECT dbo.Regex('^[0-9]','123') -- This is returning 1. SELECT dbo.Regex('^[0-9]','') -- this is not returning 1 but i want to return as 1 and i try to put space i...

asp.net mvc client side validation; manually calling validation via javascript for ajax posts

Under the built in client side validation (Microsoft mvc validation in mvc 2) using data annotations, when you try to submit a form and the fields are invalid, you will get the red validation summary next to the fields and the form will not post. However, I am using jquery form plugin to intercept the submit action on that form and doing...

adding validation annotators to model classes when using Linq-to-SQL

How should I add the following attrubute [Required(ErrorMessage="...")] to one of the model properties when my model classes are automatically generated. There is a solution here, but it seems to be working only on Entity Framework ...

Disabled asp.net button disables validation for button.

I have an aspx page that contains a checkbox, and a button. The button is disabled by default until the user checks the checkbox. It looks like when I add the attribute enabled="false" to the button, it removes the validation. When the button is enabled, I still want the validation to work. Here is the code and markup for the differe...

Silverlight4 disable textbox required validation when form loads with initial value (null)

I am trying to implement validation using IDataErrorInfo or INotifyDataErrorInfo but either way I am struggling to make it work only once user start entering data or clicking save button. Since I am using MVVM, I am setting my view's datacontext to ViewModel and my ViewModel is implementing IDataErrorInfo / INotifyDataErrorInfo. I need t...

How to fix "Byte-Order Mark found in UTF-8 File" validation warning

I've got an xhtml page validating under xhtml strict doctype -- but, I getting this warning which I trying to understand -- and correct. Just, how do I locate this errant "Byte-Order Mark". I'm editing my file using Visual Studio--not sure if that helps. Warning Byte-Order Mark found in UTF-8 File. The Unicode Byte-Order Mark...

How to change the Struts2 validation error message in the case of an invalid field value?

I'm using Struts2 validation on a web form. In the case that a field is suppose to be an integer or Date, the <s:fielderror> message I receive is a generic Invalid field value for field "[fieldname]" Naturally, I want to customize this for the user. Here's an example validation: <field name="spouseDOB"> <field-validator type="d...

java phone number validation....

Here is my problem: Create a constructor for a telephone number given a string in the form xxx-xxx-xxxx or xxx-xxxx for a local number. Throw an exception if the format is not valid. So I was thinking to validate it using a regular expression, but I don't know if I'm doing it correctly. Also what kind of exception would I have to throw...