Skip to content

Instantly share code, notes, and snippets.

@keroxp
Created June 27, 2012 12:27
Show Gist options
  • Save keroxp/3003750 to your computer and use it in GitHub Desktop.
Save keroxp/3003750 to your computer and use it in GitHub Desktop.
自分の学籍番号を認識するプログラミング
(function(){
$(function(){
var __VARS__,
ID = $("#id").val(),
red = "#CD2525",
green = "#adff2f",
blue = "#1E90FF",
$input = $("#input1");
$input.on("keydown keyup",checkID).val(ID).css("backgroundColor",green);
function checkID (e){
var chars = this.value;
if(chars.length > ID.length){
this.style.backgroundColor = red;
}else{
for(var i = 0 , max = chars.length ; i < max ; i++){
if(chars[i] != ID[i]){
this.style.backgroundColor = red;
break;
}
if(chars.length == ID.length){
this.style.backgroundColor = green;
}else{
this.style.backgroundColor = blue;
}
}
}
}
})
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment