validate

Jquery Validate success function not clearning valid labels on re-validate?

匿名 (未验证) 提交于 2019-12-03 02:29:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a form that uses JQuery Validate plugin to validate the data. For the username field (but not other fields on my form), I would like to display "Username available" next to the field if the username is available. I have this almost working. The only thing that is problematic is when the user edits the username after they enter a valid value, the previous valid message is never removed, so next to the field it reads "Username available Username available", or "Username available Username available Username available" etc. What changes

jquery - return value from callback function (in post request) into the function its inside of?

匿名 (未验证) 提交于 2019-12-03 02:27:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a javascript function that posts data to a validation script and grabs a value from there. The callback function on the post request returns a boolean value, and I'm trying to get the entire function to return that boolean value. Right now, the callback function returns the correct value, but the function itself doesn't return anything. Here's the code: function validate(request_type, request_text) { $.post("http://www.example.com/ajax/validate.php",{ type: request_type, text: request_text }, function(data) { return (data == "valid");

Dynamic jQuery Validate error messages with AddMethod based on the element

匿名 (未验证) 提交于 2019-12-03 02:24:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Let's say I have a custom AddMethod to jQuery Validate like: $.validator.addMethod('min-length', function (val, element) { // do stuff // the error message here needs to be dynamic }, 'The field cannot be less than than ' + element.attr('data-min') + // it is within the closure, but it can't grab it ' length.'); I can't figure out a way to get the element variable in question, and get any values from it. What am I missing here? 回答1: From looking at the validator source code, I think this should do it: $.validator.addMethod('min-length',

jQuery Validate resetForm() doesn't reset the onFocus validation

匿名 (未验证) 提交于 2019-12-03 02:22:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a form that is using jQuery Validate plugin for client side validation, and submits via AJAX. After the form is submitted, I would like it to reset itself. I have used the .resetForm() method to reset the fields, which works, but the problem is that the validate plugin still immediately tries to validate fields when they're focused, and gives an error before giving the new submission a chance to enter their input. Example Flow: Trigger validation initially Fix Validation, submit form via AJAX Call .resetForm(), fields are successfully

Jquery how to validate domain name

匿名 (未验证) 提交于 2019-12-03 02:22:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a input field where users can write a domain name that they wish for search for. My domain search only support searches as: "something.com" or "something" And it only support .com, .net, .org That I want to do is validate the user input before the ajax call is made and display an error message if anything is wrong. Example if a user types: "asdasdasd.asdasd" or "wwwasd.asdasd" or " www.asdasd.dk " #domainsearch is the input field #domanerknap is the search button Here is my Jquery: $(document).ready(function() { $('#domanerknap')

validate age according to date of birth using model in mvc 4

匿名 (未验证) 提交于 2019-12-03 02:22:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have registration form and its contain date of birth field. Using calender date picker its input the value to this field. these are the steps to insert value for this field step 1 step 2 step 3 so its taking values in dd/MM/yyyy format This is appearance of date of birth field in my model class [DisplayName("Date of Birth")] [DataType(DataType.Date), DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)] public Nullable<System.DateTime> Date_of_Birth { get; set; } This is appearance of date of birth field in my

jQuery form validate not working

匿名 (未验证) 提交于 2019-12-03 02:20:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I've spent hours on this and I have no idea why this jquery validate() doesn't work. I finally broke it down to minimum and it still doesn't work. This is the actuall code: <!DOCTYPE html> <html> <head> <script type="text/javascript" src="jquery-1.8.2.min.js"></script> <script type="text/javascript" src="jquery.validate.min.js"></script> <script> $(document).on("click", "#submit", function() { $("#form").validate({ rules: { input: { required: true} }, messages: { input: { required: "required" } }, ignore: "", errorClass: 'fieldError',

Regular Expression to validate a timestamp

匿名 (未验证) 提交于 2019-12-03 02:19:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I need a regular expression to validate a timestamp of the format, using Javascript : YYYY/MM/DD HH:MI:SS I tried cooking up a few, but seems my regex skills fail to cover something or other. Please give me a reference or way to do it. P.S. : I mention regex, only as a suggestion. Im using Javascript and welcome any alternative. 回答1: I would recommend to use Datejs for this. Parsing the date yourself is not necessary and a Regex is not enough to validate a timestamp. With datejs you could parse the string in a date and you'll get null if its

jQuery Validate - “Either skip these fields, or fill at least X of them”

匿名 (未验证) 提交于 2019-12-03 02:14:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm using the jQuery Validation plugin on my forms. I have some groups of fields that are optional, but need to be either "all or nothing" - if you fill one input in a group, you must fill all of them. For example, imagine the user can input one location - street, city, state, and zip - or multiple locations. You don't have to enter a second location, but if you do, it's not OK to just give the city; I need the state and zip for that one too. To solve this problem, I wrote a custom rule - really just a tiny tweak of my previous rule ,

Validate a hostname string

匿名 (未验证) 提交于 2019-12-03 02:13:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Following up to Regular expression to match hostname or IP Address? and using Restrictions on valid host names as a reference, what is the most readable, concise way to match/validate a hostname/fqdn (fully qualified domain name) in Python? I've answered with my attempt below, improvements welcome. 回答1: import re def is_valid_hostname(hostname): if len(hostname) > 255: return False if hostname[-1] == ".": hostname = hostname[:-1] # strip exactly one dot from the right, if present allowed = re.compile("(?!-)[A-Z\d-]{1,63}(?<!-)$", re