确认与校验 | Validation and verification

在向计算机输入时,为了保证输入内容的正确性,人们设计了一种自动程序自动校验输入内容,以保证程序正常运行:

书中提供了以下几种校验(Validation)的应用实例:

  1. 值域检验(Range check)
  2. 长度检验(Length check)
  3. 类型检验(Type check)
  4. 空置检验(Presence check)
  5. 格式/位数检验(Format check and check digit)

值域检验:保证用户输入的数值在一定范围内。如成绩的值域必须为0-100之间的数字。

OUTPUT "Please enter the student's mark "
REPEAT
INPUT StudentMark
IF StudentMark < 0 OR StudentMark > 100
  THEN
    OUTPUT "The student's mark should be in the range
 0 to 100, please re-enter        the mark "
ENDIF
UNTIL StudentMark >= 0 AND StudentMark <= 100

长度检验:对字符串进行长度检验。如网站注册用户名不超过20个字符;密码不超过64个字符。

OUTPUT "Please enter your password of eight
characters "
REPEAT
  INPUT Password
  IF LENGTH(Password) <> 8
    THEN
      OUTPUT "Your password must be exactly eight
 characters, please re-enter "
  ENDIF
UNTIL LENGTH(Password) = 8

类型检验:对用户输入的类型进行校验:如成绩系统要求必须输入整数(integer);用户昵称必须为字符串(string)

OUTPUT "Please enter your family name "
REPEAT
  INPUT FamilyName
  IF LENGTH(FamilyName) > 30 OR LENGTH(FamilyName) < 2
    THEN
      OUTPUT "Too short or too long,
 please re-enter "
  ENDIF
UNTIL LENGTH(FamilyName) <= 30 AND LENGTH(FamilyName) >= 2

空置检验:不得存在空值。如网站注册的用户名不能为空。

OUTPUT "How many brothers do you have? "
REPEAT
  INPUT NumberOfBrothers
  IF NumberOfBrothers <> DIV(NumberOfBrothers, 1)
    THEN
      OUTPUT "This must be a whole number, please re-enter"
  ENDIF
UNTIL NumberOfBrothers = DIV(NumberOfBrothers, 1)

格式/位数检验:要求输入的内容满足特定格式和位数。如手机号码校验:必须为1开头,长度为11位的纯数字。

OUTPUT "Please enter your email address "
REPEAT
  INPUT EmailAddress
  IF EmailAddress = ""
    THEN
      OUTPUT "*=Required "
  ENDIF
UNTIL EmailAddress <> ""

校验(Verification)的应用实例:

  1. 二次输入(Double entry)
  2. 视觉校验(Screen/visual check)

二次输入:将同样的字符输入两遍,以确保没有按错键盘或输入错我的情况。如密码要求再次输入

视觉校验:将已输入的内容再次呈现,人工检查。如提交表单之前再次提示输入的数据。

Homework: 使用Python写出两次密码校验程序

程序运行演示
暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇