The previous article share part of the function can be used normally, this sharing analysis--input verification
In order to keep the project can be learned, I will be here to share the code accumulated under, on GitHub, want to learn as soon as possible, you can directly clone my code, write code does not get started, are equal to the useless, light to see, for me, I am not able to learn.
Project Address
https://github.com/durban89/wiki_blogtag: 1.0.2
Some students may not understand, how to only give these, completely do not understand AH. I'm going to have to use the command, and follow the operation, it should be solved.
git clone https://github.com/durban89/wiki_blog /local/pathcd /local/pathgit fetch origingit checkout 1.0.2
I think that's clear enough. Ok!
Continue to share the logic of input validation.
One of the most important principles in web development is that you cannot trust any content in a client user form.
You must validate all incoming data before you use it.
Many websites are affected by this problem, which is both simple and critical.
There are two ways to validate commonly used form data.
The first is the front-end JavaScript authentication, the second is the backend server authentication.
Continue the last share, share the server-side validation in Web development Part II
Chinese
Sometimes we need users to enter their Chinese names, and we must verify that they all use Chinese instead of random characters.
For Chinese validation, the regular expression is the only method. The following example shows
if m, _ := regexp.MatchString("^[\\x{4e00}-\\x{9fa5}]+$", r.Form.Get("author")); m { fmt.Println("含有中文")}
When submitted, we give author "I am Chinese", then click Submit, you will see the output of the following content
author: [我是中文]含有中文
English alphabet
Sometimes we need users to enter only English letters.
For example, we need someone's English name, such as Astaxie rather than ASTA thank you.
We can easily use regular expressions to perform validation. The following example shows
if m, _ := regexp.MatchString("^[a-zA-Z]+$", r.Form.Get("author")); m { fmt.Println("含有英文字母")}
When submitted we give author "English", and then click Submit Submission, you will see the output of the following content
author: [English]含有英文字母
e-mail address
If you want to know if a user has entered a valid e-mail address, you can use the following regular expression:
if m, _ := regexp.MatchString(`^([\w\.\_]{2,10})@(\w{1,}).([a-z]{2,4})$`, r.Form.Get("author")); m { fmt.Println("正确的邮箱地址")}
When submitted, we assign "xxxx@qq.com" to author, and then click Submit, you will see the output as follows
author: [xxxx@qq.com]正确的邮箱地址
Project Update Address
https://github.com/durban89/typescript_demo.gittag: 1.0.3