validating

How to check whether an input conforms to an arbitrary amount of rules in Java?

为君一笑 提交于 2020-02-02 16:31:28
问题 For my specific task, I'm trying to check whether a word falls into a specified set of part of speech. This could be done like so: private boolean validate(String word) { if (isNoun(word) || isVerb(word) || isParticiple(word) || ... ) return true; else return false; } However, as you can see it quickly becomes ugly and hard to scale. If I'm testing these strings against a set of 20 rules, there should be a cleaner and more scalable way to do this. Any thoughts on how I can make my code

TextBox Events in C#

人走茶凉 提交于 2020-01-02 20:18:23
问题 I have a TextBox. After leaving the textBox the first character should be a capital Letter. Three Events work as same. They are Leave,Validating and Validated. if (txtLocl.Text.Length > 0) txtLocl.Text = txtLocl.Text.Substring(0, 1).ToUpper() + txtLocl.Text.Substring(1); Which event of these 3 events should I use? 回答1: You can subscribe to the Control.Leave event which will be fired when the control loses focus. Originally, I thought using Control.LostFocus would be the most appropriate event

Run all Validating events on the Form on button click

孤者浪人 提交于 2020-01-02 19:29:28
问题 I have a little form with some text boxes and combo boxes, each with their own validating event which just fills the default value either 1 or 0 depending on the box when the user moves on to the next box without entering anything, however i also want to run all the validations when the user just clicks on the submit button directly. private void Validating_Zero(object sender, CancelEventArgs e) { if (((TextBox_Pro)sender).Text == "") { ((TextBox_Pro)sender).Text = "0"; } } private void

Validating user input in inputbox

时间秒杀一切 提交于 2019-12-23 02:18:19
问题 When I run the following snippet, and enter an acceptable value, I get the desired result. do while len(strselect) = 0 'or strselect<>"1" or strselect<>"2" or strselect<>"3" strselect = inputbox ("Please select:" &vbcrlf&vbcrlf&_ "1. Add an entry" &vbcrlf&vbcrlf&_ "2. Remove an entry" &vbcrlf&vbcrlf&_ "3. Search for an entry" &vbcrlf, "Contact Book") if isempty(strselect) then wscript.quit() elseif strselect="1" then wscript.echo "You chose 1" elseif strselect="2" then wscript.echo "You chose

How to make HTML input tag only accept numerical values?

纵然是瞬间 提交于 2019-12-17 02:09:11
问题 I need to make sure that a certain <input> field only takes numbers as value. The input is not part of a form. Hence it doesn't get submitted, so validating during submission is not an option. I want the user to be unable to type in any characters other than numbers. Is there a neat way to achieve this? 回答1: HTML 5 You can use HTML5 input type number to restrict only number entries: <input type="number" name="someid" /> This will work only in HTML5 complaint browser. Make sure your html

TextBox Events in C#

戏子无情 提交于 2019-12-08 07:32:29
I have a TextBox. After leaving the textBox the first character should be a capital Letter. Three Events work as same. They are Leave,Validating and Validated. if (txtLocl.Text.Length > 0) txtLocl.Text = txtLocl.Text.Substring(0, 1).ToUpper() + txtLocl.Text.Substring(1); Which event of these 3 events should I use? You can subscribe to the Control.Leave event which will be fired when the control loses focus. Originally, I thought using Control.LostFocus would be the most appropriate event to use but it is not available via the designer meaning you would need to manually subscribe to the event

Validating input with while loop and scanner

无人久伴 提交于 2019-12-06 14:50:02
问题 What's the best way about getting a valid integer from a user that is in a specified range (0,20) and is an int . If they enter an invalid integer print out error. I am thinking something like: int choice = -1; while(!scanner.hasNextInt() || choice < 0 || choice > 20) { System.out.println("Error"); scanner.next(); //clear the buffer } choice = scanner.nextInt(); Is this correct or is there a better way? 回答1: Where do you change choice inside of your while loop? If it's not changed you can't

Validating input with while loop and scanner

强颜欢笑 提交于 2019-12-04 21:59:21
What's the best way about getting a valid integer from a user that is in a specified range (0,20) and is an int . If they enter an invalid integer print out error. I am thinking something like: int choice = -1; while(!scanner.hasNextInt() || choice < 0 || choice > 20) { System.out.println("Error"); scanner.next(); //clear the buffer } choice = scanner.nextInt(); Is this correct or is there a better way? Where do you change choice inside of your while loop? If it's not changed you can't expect to use it in your if block's boolean condition. You'll have to check that the Scanner doesn't have an

validating 10 characters, can only be numbers, then redirecting to a web address

℡╲_俬逩灬. 提交于 2019-12-04 06:30:58
问题 So what I need to have happen: User types in 10 digits (only digits) and clicks “Submit” On submit – the user gets redirected to another landing page. Here is what I’ve done…and its redirecting, but not really validating the 10 characters, or that they are digits. I have another script that does that, but not both together as they use different programming langauges. <script type="text/javascript" src="http://dev.jquery.com/view/trunk/plugins/validate/jquery.validate.js"></script> <script> $

Why is moment.js allowing date with one digit year when using strict parsing?

你离开我真会死。 提交于 2019-12-04 04:20:23
问题 I am using moment.js to parse a date. http://momentjs.com/docs/#/parsing/string-format/ This is to validate and convert the date to a format required by my database. In my testing I encountered this input date '6-4-3' which should not be valid with the given format. moment('6-4-3','YYYY-MM-DD',true).isValid(); //returns true The resulting date in the moment object is "Mon Apr 03 0006 ...". When I call isValid, it returns true. I think it should consider this date invalid because it has too