JAvascriptの各種条件の1.テキストボックス入力制限入力制限


1.テキストボックス入力制限
大、小文字英語、数字、浮動小数点数、日付、中国語、一部英語、一部中国語など多くの機能の入力制限を実現する.htmlコードに直接追加すれば使用できます.
<script>
function regInput(obj, reg, inputStr)
{
var docSel = document.selection.createRange()
if (docSel.parentElement().tagName != "INPUT") return false
oSel = docSel.duplicate()
oSel.text = ""
var srcRange = obj.createTextRange()
oSel.setEndPoint("StartToStart", srcRange)
var str = oSel.text + inputStr + srcRange.text.substr(oSel.text.length)
return reg.test(str)
}
</script>

小文字英語:
<xmp style= "display:inline"> </xmp>
<input onkeypress = "return regInput(this, /^[a-z]*$/, String.fromCharCode(event.keyCode))"
onpaste = "return regInput(this, /^[a-z]*$/, window.clipboardData.getData('Text'))"
ondrop = "return regInput(this, /^[a-z]*$/, event.dataTransfer.getData('Text'))"
style="ime-mode:Disabled"><br>

大文字:
<xmp style= "display:inline"> </xmp>
<input onkeypress = "return regInput(this, /^[A-Z]*$/, String.fromCharCode(event.keyCode))"
onpaste = "return regInput(this, /^[A-Z]*$/, window.clipboardData.getData('Text'))"
ondrop = "return regInput(this, /^[A-Z]*$/, event.dataTransfer.getData('Text'))"
style="ime-mode:Disabled">
<br>

任意の数値:
<xmp style="display:inline"> </xmp>
<input onkeypress = "return regInput(this, /^[0-9]*$/, String.fromCharCode(event.keyCode))"
onpaste = "return regInput(this, /^[0-9]*$/, window.clipboardData.getData('Text'))"
ondrop = "return regInput(this, /^[0-9]*$/, event.dataTransfer.getData('Text'))"
style="ime-mode:Disabled"><br>

小数2桁まで:
<xmp style="display:inline"> </xmp>
<input onkeypress = "return regInput(this, /^\d*\.?\d{0,2}$/,
String.fromCharCode(event.keyCode))"
onpaste = "return regInput(this, /^\d*\.?\d{0,2}$/,
window.clipboardData.getData('Text'))"
ondrop = "return regInput(this, /^\d*\.?\d{0,2}$/,
event.dataTransfer.getData('Text'))"
style="ime-mode:Disabled">

例:123.12

日付:
<xmp style="display:inline"> </xmp>

<input onkeypress = "return regInput(this, /^\d{1,4}
([-\/](\d{1,2}([-\/](\d{1,2})?)?)?)?$/,
String.fromCharCode(event.keyCode))"

onpaste = "return regInput(this, /^\d{1,4}([-\/](\d{1,2}
([-\/](\d{1,2})?)?)?)?$/,
window.clipboardData.getData('Text'))"

ondrop = "return regInput(this, /^\d{1,4}([-\/](\d{1,2}
([-\/](\d{1,2})?)?)?)?$/,
event.dataTransfer.getData('Text'))"

style="ime-mode:Disabled">

例えば:2002-9-29

任意の中国語
<xmp style="display:inline"> </xmp>

<input onkeypress = "return regInput(this, /^$/,
String.fromCharCode(event.keyCode))"

onpaste = "return regInput(this, /^[\u4E00-\u9FA5]*$/,
window.clipboardData.getData('Text'))"

ondrop = "return regInput(this, /^[\u4E00-\u9FA5]*$/,
event.dataTransfer.getData('Text'))"><br>

英語:
<xmp style="display:inline"> </xmp>
<input onkeypress = "return regInput(this, /^[a-e]*$/,
String.fromCharCode(event.keyCode))"

onpaste = "return regInput(this, /^[a-e]*$/,
window.clipboardData.getData('Text'))"

ondrop = "return regInput(this, /^[a-e]*$/,
event.dataTransfer.getData('Text'))"

style="ime-mode:Disabled">

範囲:a,b,c,d,e

部分日文:

function checkChinese(oldLength, obj)
{
var oTR = window.document.selection.createRange()
var reg=/[^一二三四五六七八九十]/g
oTR.moveStart("character", -1*(obj.value.length-oldLength))
oTR.text = oTR.text.replace(reg, "")
}

"setTimeout('checkChinese('+this.value.length+','+this.uniqueID+')',
1)"
onpaste="return regInput(this,/^[一二三四五六七八九]*$/,
window.clipboardData.getData('Text'))"
ondrop="return regInput(this,/^[一二三四五六七八九]*$/,
event.dataTransfer.getData('Text'))">
範囲:一二三四五六七八九0

2.右クリックを展開できない、すべて選択できない、コピーできない実装
<body oncontextmenu="window.event.returnvalue=false"
onkeypress="window.event.returnvalue=false"
onkeydown="window.event.returnvalue=false"
onkeyup="window.event.returnvalue=false"
ondragstart="window.event.returnvalue=false"
onselectstart="event.returnvalue=false">
...


3.ページ本文の内容の選択を禁止する

<body oncontextmenu="return false" ondragstart="return false"
onselectstart ="return false" onselect="document.selection.empty()"
oncopy="document.selection.empty()" onbeforecopy="return false"onmouseup="document.selection.empty()">

4.Webページをフレームワークに入れない
<script language=“javascript”><!--if (self!=top){top.location=self.location;}-->< /script>

5.表示禁止ソースコード
<frameset>
<frame src="        URL">
</frameset>

6.クローズ入力方式
<input style="ime-mode:disabled">

7.画像ダウンロード禁止
ここでの最後の参加:
oncontextmenu="return false" ondragstart="return false" onselectstart="return
false" scroll="auto"

8.キャッシュ禁止
 HEAD   :

<meta http-equiv="Expires" CONTENT="0">
<meta http-equiv="Cache-Control" CONTENT="no-cache">
<meta http-equiv="Pragma" CONTENT="no-cache">