19 表单验证&上传图片验证

表单验证

 1 <!DOCTYPE html>
 2 <html lang="en">
 3 <head>
 4     <meta charset="UTF-8">
 5     <title>表单验证</title>
 6     <style type="text/css">
 7         *{
 8             padding:0;
 9             margin:0;
10         }
11         .box{
12             margin:100px auto;
13             width:500px;
14             border:1px solid darkgray;
15             padding:20px;
16         }
17         #prompt{
18             font-size: 12px;
19             color: darkgray;
20         }
21         .right{
22             color: lightgreen !important;
23             background: url(‘images/right.png‘) no-repeat 5px center;
24             background-size: 15px;
25             padding-left:25px;
26         }
27         .error{
28             color: red !important;;
29             background: url(‘images/error.png‘) no-repeat 5px center;
30             background-size: 15px;
31             padding-left:25px;
32         }
33     </style>
34 </head>
35 <body>
36 <div class="box">
37     <label for="score">Your score: </label>
38     <input type="text" id="score" placeholder="Please input your score...">
39     <span id="prompt">Please input your score...</span>
40     <!--<span class="right">The score is right.</span>-->
41     <!--<span class="error">The score must be numbers!</span>-->
42     <!--<span class="error">The score must between 0 and 100!</span>-->
43 </div>
44 </body>
45 <script type="text/javascript">
46     function $(id) {
47         return typeof id === ‘string‘ ? document.getElementById(id):null;
48     }
49     window.onload = function () {
50         $(‘score‘).onblur = function () {
51             var val = this.value.trim();
52             if(val.length == 0){
53                 $(‘prompt‘).className = ‘error‘;
54                 $(‘prompt‘).innerText = "The score can‘t be empty!";
55             }else if(!parseFloat(val)){
56                 $(‘prompt‘).className = ‘error‘;
57                 $(‘prompt‘).innerText = "The score must be numbers!";
58             }else if(val>=0 && val<=100){
59                 $(‘prompt‘).className = ‘right‘;
60                 $(‘prompt‘).innerText = "The score is right.";
61             }else{
62                 $(‘prompt‘).className = ‘error‘;
63                 $(‘prompt‘).innerText = "The score must between 0 and 100!";
64             }
65         }
66         $(‘score‘).onfocus = function () {
67             $(‘prompt‘).className = ‘‘;
68             $(‘prompt‘).innerText = "Please input your score...";
69             this.value = ‘‘;
70         }
71     }
72 </script>
73 </html>

上传图片验证

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>上传图片验证</title>
    <style type="text/css">
        *{
            padding:0;
            margin:0;
        }
        .box{
            margin:100px auto;
            width:500px;
            border:1px solid darkgray;
            padding:20px;
            border-radius:5px;
        }
    </style>
</head>
<body>
<div class="box">
    <form action="javascript:void(0)">
        <label for="file">图片格式验证</label>
        <input type="file" id="file" >
    </form>
</div>
</body>
<script type="text/javascript">
    var patt = /.+\.jpg$|png$|jpeg$|gif$/ig;
    window.onload = function () {
        var inp = document.getElementById(‘file‘);
        inp.onchange = function () {
            if(patt.exec(inp.value.toLowerCase())){
                alert(‘Right‘);
            }else{
                alert(‘False‘);
            }
        }
    }
</script>
</html>

原文地址:https://www.cnblogs.com/znyyy/p/11129823.html

时间: 2024-08-01 06:21:22

19 表单验证&上传图片验证的相关文章

在Tomcat中采用基于表单的安全验证

1.概述   (1)基于表单的验证 基于From的安全认证可以通过TomcatServer对Form表单中所提供的数据进行验证,基于表单的验证使系统开发者可以自定义用户的登陆页面和报错页面.这种验证方法与基本HTTP的验证方法的唯一区别就在于它可以根据用户的要求制定登陆和出错页面. 通过拦截并检查用户的请求,检查用户是否在应用系统中已经创建好login session.如果没有,则将用户转向到认证服务的登录页面.但在Tomcat中的基于表单的验证凭证不被保护并以纯文本发送.   (2)在Tomc

[Swift通天遁地]二、表格表单-(8)快速实现表单的输入验证

本文将演示如何快速实现表单是输入验证. 首先确保在项目中已经安装了所需的第三方库. 点击[Podfile],查看安装配置文件. 1 platform :ios, '12.0' 2 use_frameworks! 3 4 target 'DemoApp' do 5 source 'https://github.com/CocoaPods/Specs.git' 6 pod 'SwiftValidator', :git => 'https://github.com/jpotts18/SwiftVali

js 验证表单 js提交验证类

js 验证表单 js提交验证类 附加:js验证radio是否选择 <script language="javascript">function checkform(obj){for(i=0;i<obj.oo.length;i++)         if(obj.oo[i].checked==true) return true; alert("请选择")return false; }</script><form id="f

第一百八十六节,jQuery,验证表单插件,Ajax 表单插件,验证和提交表单

jQuery,验证表单插件,Ajax 表单插件,验证和提交表单 HTML <form id="reg" method="post" action="yzh.php" title="会员注册"> <ol class="reg_error"></ol> <p> <label for="user">帐号:</label>

html表单提交数据验证

我们在做B/S项目开发中,经常会用到表单提交数据,在页面需要做js数据验证,简单方法如下 js部分: <script type="text/javascript"> function validate_required(field, alerttxt) { with (field) { if (value == null || value == "") { alert(alerttxt); return false } else { return tru

yii表单的各种验证

/验证规则详细配置 public function rules() { // NOTE: you should only define rules for those attributes that // will receive user inputs. return array( array('username', 'required' ,'message'=>'用户名必须填写'), // array('username', 'required' ,'requiredValue'=>'ab

UI标签库专题三:JEECG智能开发平台 FormValidation(表单提交及验证标签)

?? 1. FormValidation(表单提交及验证标签) 1.1.  参数 属性名 类型 描述 是否必须 默认值 action string 表单提交路径 否 null formid string 表单唯一标示 是 formobj refresh boolean dialog为true时是否刷新父页面 否 true callback string 表单提交完成后的回调函数 否 null beforeSubmit string 表单提交前的处理函数 否 null btnsub string

javascprit form表单提交前验证以及ajax返回json

1.今天要做一个手机验证码验证的功能.需求是前端页面点击发送 短信验证码,后台接收后通过ajax返回到前端,之后前端在提交时候进行验证.思路很简单,不过做的过程还是学到不少的东西. 1.ajax请求后返回 returning 405 Method Not Allowed 原因是我后台返回的时候没有加上: @ResponseBody注解.加上后返回的数据是json字符串,但是js只能操作json对象.需要把json字符串转为json对象.一般的有三种方式1.JSON.parse();如 var j

js小插件-html表单的静态验证

 html表单静态验证: 对于表单的验证,大多数时候都是交由服务器完成,那为什么在html中还要做这个事情呢?但是呢,如果把所有的信息都交由服务器处理,会加大服务器的负担,并且对于服务器来说一些不合法的信息验证完全没必要. 所以呢,在html中简单的验证一下表单是有必要的,一来是为了减轻服务器的负担,二来也是为了给用户的一些简单的操作提示,以输入合法的信息. 所谓的静态验证,就是再不需要服务器的情况下由html自身就可完成的验证,在html中我们可以简单的验证一下我们要提交的表单信息,验证通

ASP.NET 4.0 取消表单危险字符验证

/// <summary> /// ASP.NET4.0 表单验证类 /// </summary> public class FormRequestValidation : RequestValidator { public FormRequestValidation() { } protected override bool IsValidRequestString(HttpContext context, string value, RequestValidationSourc