Use CSS to automatically add ‘required field’ asterisk to form inputs

Is that what you had in mind? http://jsfiddle.net/erqrN/1/ <label class=”required”>Name:</label> <input type=”text”> <style> .required:after { content:” *”; color: red; } </style> .required:after { content:” *”; color: red; } <label class=”required”>Name:</label> <input type=”text”> See https://developer.mozilla.org/en-US/docs/Web/CSS/pseudo-elements

Validation using Validating event and ErrorProvider – Show Error Summary

You should first correct your validating events this way: private void textBox1_Validating(object sender, CancelEventArgs e) { Regex regex1 = new Regex(@”^[a-zA-Z]+$”); if (!regex1.IsMatch(textBox1.Text)) { //To set validation error errorProvider1.SetError(textBox1, “Nosaukums nedrīskt saturēt ciparus!”); //To say the state of control in invalid e.Cancel = true; } else { //To clear the validation error this.errorProvider1.SetError(this.textBox1, “”); } … Read more

Validate object based on external factors (ie. data store uniqueness)

I would suggest an experiment that i have only been trialling for the last week or so. Based on this inspiration i am creating DTOs that validate a little differently to that of the DataAnnotations approach. Sample DTO: public class Contact : DomainBase, IModelObject { public int ID { get; set; } public string Name … Read more

HTML/JavaScript: Simple form validation on submit

You have several errors there. First, you have to return a value from the function in the HTML markup: <form name=”ff1″ method=”post” onsubmit=”return validateForm();”> Second, in the JSFiddle, you place the code inside onLoad which and then the form won’t recognize it – and last you have to return true from the function if all … Read more

Custom Validation Attributes: Comparing two properties in the same model

You can create a custom validation attribute for comparison two properties. It’s a server side validation: public class MyViewModel { [DateLessThan(“End”, ErrorMessage = “Not valid”)] public DateTime Begin { get; set; } public DateTime End { get; set; } } public class DateLessThanAttribute : ValidationAttribute { private readonly string _comparisonProperty; public DateLessThanAttribute(string comparisonProperty) { _comparisonProperty … Read more

Is it possible to validate the size and type of input=file in html5

<form class=”upload-form”> <input class=”upload-file” data-max-size=”2048″ type=”file” > <input type=submit> </form> <script> $(function(){ var fileInput = $(‘.upload-file’); var maxSize = fileInput.data(‘max-size’); $(‘.upload-form’).submit(function(e){ if(fileInput.get(0).files.length){ var fileSize = fileInput.get(0).files[0].size; // in bytes if(fileSize>maxSize){ alert(‘file size is more then’ + maxSize + ‘ bytes’); return false; }else{ alert(‘file size is correct- ‘+fileSize+’ bytes’); } }else{ alert(‘choose file, please’); return … Read more