我正在编写一个必须接受用户输入的程序.
#note: Python 2.7 users should use `raw_input`, the equivalent of 3.X's `input`
age = int(input("Please enter your age: "))
if age >= 18:
print("You are able to vote in the United States!")
else:
print("You are not able to vote in the United States.")
Run Code Online (Sandbox Code Playgroud)
如果用户输入合理数据,这将按预期工作.
C:\Python\Projects> canyouvote.py
Please enter your age: 23
You are able to vote in the United States!
Run Code Online (Sandbox Code Playgroud)
但如果他们犯了错误,那就崩溃了:
C:\Python\Projects> canyouvote.py
Please enter your age: dickety six
Traceback (most recent call last):
File "canyouvote.py", line 1, in …Run Code Online (Sandbox Code Playgroud) 哪些字符使网址无效?
这些有效的网址是?
example.com/file[/].htmlhttp://example.com/file[/].html我有一个表格,我希望所有字段都填写.如果一个字段被点击,然后没有填写,我想显示一个红色背景.
这是我的代码:
$('#apply-form input').blur(function () {
if ($('input:text').is(":empty")) {
$(this).parents('p').addClass('warning');
}
});
Run Code Online (Sandbox Code Playgroud)
无论填写的字段是否填写,它都会应用警告类.
我究竟做错了什么?
在我的表单中,我想使用新的HTML5表单类型,例如<input type="url" />(有关这里类型的更多信息).
The problem is that Chrome wants to be super helpful and validate these elements for me, except that it sucks at it. If it fails the built-in validation, there's no message or indication other than the element getting focus. I prefill URL elements with "http://", and so my own custom validation just treats those values as empty strings, however Chrome rejects that. If I could change its validation rules, that would work …
每当我在基于Django/Piston的REST API应用程序中遇到验证失败时,我目前正在返回401 Unauthorized .看过HTTP状态代码注册表后 我不相信这是验证失败的合适代码,你们都推荐什么?
更新:上面的"验证失败"表示应用程序级别数据验证失败,即错误指定日期时间,虚假电子邮件地址等.
我在我的项目中使用eclipse,在弄乱我的eclipse设置时,我启用了Javascript支持.现在eclipse抱怨JQuery库中有错误,并且不让我编译项目.有谁知道如何关闭javascript验证?
有谁知道如何在Swift中验证电子邮件地址?我找到了这段代码:
- (BOOL) validEmail:(NSString*) emailString {
if([emailString length]==0){
return NO;
}
NSString *regExPattern = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
NSRegularExpression *regEx = [[NSRegularExpression alloc] initWithPattern:regExPattern options:NSRegularExpressionCaseInsensitive error:nil];
NSUInteger regExMatches = [regEx numberOfMatchesInString:emailString options:0 range:NSMakeRange(0, [emailString length])];
NSLog(@"%i", regExMatches);
if (regExMatches == 0) {
return NO;
} else {
return YES;
}
}
Run Code Online (Sandbox Code Playgroud)
但我不能把它翻译成斯威夫特.
我有以下HTML5表单:http://jsfiddle.net/nfgfP/
<form id="form" onsubmit="return(login())">
<input name="username" placeholder="Username" required />
<input name="pass" type="password" placeholder="Password" required/>
<br/>Remember me: <input type="checkbox" name="remember" value="true" /><br/>
<input type="submit" name="submit" value="Log In"/>Run Code Online (Sandbox Code Playgroud)
目前当我在空白时点击输入时,会出现一个弹出框,上面写着"请填写此字段".如何将该默认消息更改为"此字段不能留空"?
编辑:另请注意,类型密码字段的错误消息很简单*****.要重新创建此项,请为用户名提供值并点击提交.
编辑:我正在使用Chrome 10进行测试.请这样做
我有一个输入只能有2个值apple或banana.我可以使用什么正则表达式来确保提交两个单词中的任何一个?
validation ×10
forms ×3
jquery ×3
email ×2
html5 ×2
javascript ×2
eclipse ×1
html ×1
input ×1
ios ×1
loops ×1
python ×1
python-3.x ×1
regex ×1
rest ×1
rfc3986 ×1
swift ×1
syntax ×1
url ×1
user-input ×1