Re: javascript validation
Hello
if you want to check only one char I prefer this way more than using regExp
HTML Code:
<script type="text/javascript">
var fineChars = '123456abcdef';
function checkChar(inputField)
{
var pressedChar = inputField.value.substring(inputField.value.length - 1, inputField.value.length);
if (fineChars.indexOf(pressedChar) == -1) {
var newValue = inputField.value.substring(0, inputField.value.length - 1);
inputField.value = newValue;
}
}
</script>
<input type="text" onkeyup="checkChar(this)" />
regards :)
Feras Jobeir
Re: javascript validation
Hello
If you want to check a char only, I prefer to try this more that using RegExp
HTML Code:
<script type="text/javascript">
var fineChars = '123456abcdef';
function checkChar(inputField)
{
var pressedChar = inputField.value.substring(inputField.value.length - 1, inputField.value.length);
if (fineChars.indexOf(pressedChar) == -1) {
var newValue = inputField.value.substring(0, inputField.value.length - 1);
inputField.value = newValue;
}
}
</script>
<input type="text" onkeyup="checkChar(this)" />
regards :)
Feras Jobeir
Re: javascript validation
Tnx for your replys guys, but i managed to do this on my own..
This is how i did it:
Code:
onkeyup="input_res(this,'abC chars to be allowed')
function input_res(object,validation){
var result = "";
for (i=0; i < object.value.length; i++) {
x = object.value.charAt(i);
if (validation.indexOf(x,0) != -1) {
result += x;
}
}
object.value = result
}
Good luck to everyone