removed all the footers; formated all the files
This commit is contained in:
15
4.2.md
15
4.2.md
@@ -29,7 +29,7 @@
|
||||
}
|
||||
|
||||
还有一种方式就是正则匹配的方式
|
||||
|
||||
|
||||
if m, _ := regexp.MatchString("^[0-9]+$", r.Form.Get("age")); !m {
|
||||
return false
|
||||
}
|
||||
@@ -76,13 +76,13 @@
|
||||
如果我们想要判断表单里面`<select>`元素生成的下拉菜单中是否有被选中的项目。有些时候黑客可能会伪造这个下拉菜单不存在的值发送给你,那么如何判断这个值是否是我们预设的值呢?
|
||||
|
||||
我们的select可能是这样的一些元素
|
||||
|
||||
|
||||
<select name="fruit">
|
||||
<option value="apple">apple</option>
|
||||
<option value="pear">pear</option>
|
||||
<option value="banane">banane</option>
|
||||
</select>
|
||||
|
||||
|
||||
那么我们可以这样来验证
|
||||
|
||||
slice:=[]string{"apple","pear","banane"}
|
||||
@@ -93,7 +93,7 @@
|
||||
}
|
||||
}
|
||||
return false
|
||||
|
||||
|
||||
上面这个函数包含在我开源的一个库里面(操作slice和map的库),[https://github.com/astaxie/beeku](https://github.com/astaxie/beeku)
|
||||
|
||||
## 单选按钮
|
||||
@@ -129,7 +129,7 @@
|
||||
}
|
||||
|
||||
return false
|
||||
|
||||
|
||||
|
||||
## 日期和时间
|
||||
你想确定用户填写的日期或时间是否有效。例如
|
||||
@@ -155,12 +155,9 @@ Go里面提供了一个time的处理包,我们可以把用户的输入年月
|
||||
return false
|
||||
}
|
||||
|
||||
上面列出了我们一些常用的服务器端的表单元素验证,希望通过这个引导入门,能够让你对Go的数据验证有所了解,特别是Go里面的正则处理。
|
||||
上面列出了我们一些常用的服务器端的表单元素验证,希望通过这个引导入门,能够让你对Go的数据验证有所了解,特别是Go里面的正则处理。
|
||||
|
||||
## links
|
||||
* [目录](<preface.md>)
|
||||
* 上一节: [处理表单的输入](<4.1.md>)
|
||||
* 下一节: [预防跨站脚本](<4.3.md>)
|
||||
|
||||
## LastModified
|
||||
* $Id$
|
||||
Reference in New Issue
Block a user