Blogroll

Pages

Tutorial Inputan hanya angka dengan javascript ,

Selasa, 17 Desember 2013

everybody selamat pagi , validasi sangatlah penting di dalam pemograman , nah untuk mempermudah kita validasi dan lainnya sehingga kita tidak perlu repot-repot , cek sana - cek sini ,, mendingan kita batasi aja
karena cukup banyak user yang salah pencet dll ,,

biasanya kita membutuhkan inputan yang harusnya diisi oleh angka saja ,,

okeh tinggal copas saja deh code nya neh ,, :D ..
selamat mencoba ,,

<script character.match="" code="" else="" false="" if="" restrictiontype="" return="" script="" true="" type="text/javascript&gt;
var integerOnly = /[0-9\.]/g;
var digitsOnly = /[1234567890]/g;
var alphaOnly = /[A-Za-z]/g;
function restrictCharacters(myfield, e, restrictionType) {
if (!e) var e = window.event
if (e.keyCode) code = e.keyCode;
else if (e.which) code = e.which;
var character = String.fromCharCode(code);
// if they pressed esc... remove focus from field...
if (code==27) { this.blur(); return false; }
// ignore if they are press other keys
// strange because code: 39 is the down key AND ' key...
// and DEL also equals .
if (!e.ctrlKey &amp;&amp; code!=9 &amp;&amp; code!=8 &amp;&amp; code!=36 &amp;&amp; code!=37 &amp;&amp; code!=38 &amp;&amp; (code!=39 || (code==39 &amp;&amp; character==">

<input type="text" name="angka"onkeypress="return restrictCharacters(this, event, digitsOnly);" />
</pre>
</script>

Tidak ada komentar:

Posting Komentar