在asp.net中屏蔽和验证yyyy-yy格式? [英] Masking and validation for yyyy-yy format in asp.net?

查看:103
本文介绍了在asp.net中屏蔽和验证yyyy-yy格式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望用户以yyyy-yy格式在文本框中输入会话。我想掩盖它。如何强制和验证?

I want the user to enter session in textbox in the format yyyy-yy. I want masking for that. How to force and validate this?

推荐答案

如果你没有找到满足你需求的屏蔽控件,那么只需处理 keypress 文本框的事件并检查内容的长度。如果内容长度为4,则插入 - ,然后再允许两个字符。
If you did not find a masking control for your requirement, then just handle the keypress event for the textbox and check the length of the content. If content length is 4, then insert a "-", then allow two more characters.


keypress 事件将更合适。

尝试按键 jquery事件:





首先只允许使用 maxlength 属性在文本框中输入7个字符

: keypress event will be more appropriate.
Try keypress event of jquery :


First allow only 7 characters in your text box by using maxlength property
<input type="text" id="txtInput"  maxlength="7" />





然后在jquery中写 keypress

事件:





then write keypress
event in jquery :


document )。ready( function (){
(document).ready(function () {


这篇关于在asp.net中屏蔽和验证yyyy-yy格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆