for(var i= 0; i < foundRecords.length ; i++){
var MaleChildNew=0,
MaleNew=0,
femaleChildNew=0,
femaleNew=0,
policeMaleChildNew = 0,
policefemaleChildNew=0,
policeMaleNew=0,
policefemaleNew=0,
npoliceMaleChildNew=0,
npoliceMaleNew=0,
npolicefemaleChildNew=0,
npolicefemaleNew=0;
if(foundRecords[i]['age'] <= 12 && foundRecords[i]['patientType'] == 'policePerson' && foundRecords[i]['sex'] == 'male' && foundRecords[i]['opdType'] == 'new' ){
policeMaleChildNew++;
}else if(foundRecords[i]['age'] <= 12 && foundRecords[i]['patientType'] == 'policePerson' && foundRecords[i]['sex'] == 'female' && foundRecords[i]['opdType'] == 'new' ){
policefemaleChildNew++;
}else if(foundRecords[i]['age'] > 12 && foundRecords[i]['patientType'] == 'policePerson' && foundRecords[i]['sex'] == 'male' && foundRecords[i]['opdType'] == 'new' ){
policeMaleNew++;
}else if(foundRecords[i]['age'] > 12 && foundRecords[i]['patientType'] == 'policePerson' && foundRecords[i]['sex'] == 'female' && foundRecords[i]['opdType'] == 'new' ){
policefemaleNew++;
} if(foundRecords[i]['age'] <= 12 && foundRecords[i]['patientType'] == 'policePerson' && foundRecords[i]['sex'] == 'male' && foundRecords[i]['opdType'] == 'new' ){
npoliceMaleChildNew++;
}else if(foundRecords[i]['age'] <= 12 && foundRecords[i]['patientType'] == 'policePerson' && foundRecords[i]['sex'] == 'female' && foundRecords[i]['opdType'] == 'new' ){
npolicefemaleChildNew++;
}else if(foundRecords[i]['age'] > 12 && foundRecords[i]['patientType'] == 'policePerson' && foundRecords[i]['sex'] == 'male' && foundRecords[i]['opdType'] == 'new' ){
npoliceMaleNew++;
}else if(foundRecords[i]['age'] > 12 && foundRecords[i]['patientType'] == 'policePerson' && foundRecords[i]['sex'] == 'female' && foundRecords[i]['opdType'] == 'new' ){
npolicefemaleNew++;
} if(foundRecords[i]['age'] <= 12 && foundRecords[i]['patientType'] == 'policePerson' && foundRecords[i]['sex'] == 'male' && foundRecords[i]['opdType'] == 'new' ){
MaleChildNew++;
}else if(foundRecords[i]['age'] <= 12 && foundRecords[i]['patientType'] == 'policePerson' && foundRecords[i]['sex'] == 'female' && foundRecords[i]['opdType'] == 'new' ){
femaleChildNew++;
}else if(foundRecords[i]['age'] > 12 && foundRecords[i]['patientType'] == 'policePerson' && foundRecords[i]['sex'] == 'male' && foundRecords[i]['opdType'] == 'new' ){
MaleNew++;
}else if(foundRecords[i]['age'] > 12 && foundRecords[i]['patientType'] == 'policePerson' && foundRecords[i]['sex'] == 'female' && foundRecords[i]['opdType'] == 'new' ){
femaleNew++;
}
}
The problem is that it only increments the category which it finds in the end of the database and returns 1 for the same. What I want is that it should increment the value for every entry it finds similar and save the value. But this code returns 0 for all other variables and 1 for the one which is at the end of the DB.
Your code will always initialise the variables to 0 as they are inside the for loop. So, the variables are reset to 0 for each item of foundRecords. Thus, declare your variables outside the for loop:
var MaleChildNew=0,
MaleNew=0,
femaleChildNew=0,
femaleNew=0,
policeMaleChildNew = 0,
policefemaleChildNew=0,
policeMaleNew=0,
policefemaleNew=0,
npoliceMaleChildNew=0,
npoliceMaleNew=0,
npolicefemaleChildNew=0,
npolicefemaleNew=0;
for(var i= 0; i < foundRecords.length ; i++){
if(foundRecords[i]['age'] <= 12 && foundRecords[i]['patientType'] == 'policePerson' && foundRecords[i]['sex'] == 'male' && foundRecords[i]['opdType'] == 'new' ){
policeMaleChildNew++;
}else if(foundRecords[i]['age'] <= 12 && foundRecords[i]['patientType'] == 'policePerson' && foundRecords[i]['sex'] == 'female' && foundRecords[i]['opdType'] == 'new' ){
policefemaleChildNew++;
}else if(foundRecords[i]['age'] > 12 && foundRecords[i]['patientType'] == 'policePerson' && foundRecords[i]['sex'] == 'male' && foundRecords[i]['opdType'] == 'new' ){
policeMaleNew++;
}else if(foundRecords[i]['age'] > 12 && foundRecords[i]['patientType'] == 'policePerson' && foundRecords[i]['sex'] == 'female' && foundRecords[i]['opdType'] == 'new' ){
policefemaleNew++;
} if(foundRecords[i]['age'] <= 12 && foundRecords[i]['patientType'] == 'policePerson' && foundRecords[i]['sex'] == 'male' && foundRecords[i]['opdType'] == 'new' ){
npoliceMaleChildNew++;
}else if(foundRecords[i]['age'] <= 12 && foundRecords[i]['patientType'] == 'policePerson' && foundRecords[i]['sex'] == 'female' && foundRecords[i]['opdType'] == 'new' ){
npolicefemaleChildNew++;
}else if(foundRecords[i]['age'] > 12 && foundRecords[i]['patientType'] == 'policePerson' && foundRecords[i]['sex'] == 'male' && foundRecords[i]['opdType'] == 'new' ){
npoliceMaleNew++;
}else if(foundRecords[i]['age'] > 12 && foundRecords[i]['patientType'] == 'policePerson' && foundRecords[i]['sex'] == 'female' && foundRecords[i]['opdType'] == 'new' ){
npolicefemaleNew++;
} if(foundRecords[i]['age'] <= 12 && foundRecords[i]['patientType'] == 'policePerson' && foundRecords[i]['sex'] == 'male' && foundRecords[i]['opdType'] == 'new' ){
MaleChildNew++;
}else if(foundRecords[i]['age'] <= 12 && foundRecords[i]['patientType'] == 'policePerson' && foundRecords[i]['sex'] == 'female' && foundRecords[i]['opdType'] == 'new' ){
femaleChildNew++;
}else if(foundRecords[i]['age'] > 12 && foundRecords[i]['patientType'] == 'policePerson' && foundRecords[i]['sex'] == 'male' && foundRecords[i]['opdType'] == 'new' ){
MaleNew++;
}else if(foundRecords[i]['age'] > 12 && foundRecords[i]['patientType'] == 'policePerson' && foundRecords[i]['sex'] == 'female' && foundRecords[i]['opdType'] == 'new' ){
femaleNew++;
}
}
Related
I'm trying to make the input takes only the value 99.999. I don't want to use MaxLength because it would not calculate the length of the decimal digits. I don't want to use any other functions that erase when it doesn't match a specific regex. I want it to stop it in the input.
function IsCurrencyNoMinus1 (e, thisobj, min, max) {
var keyCode = e.keyCode == 0 ? e.charCode : e.keyCode;
var ret = ((keyCode >= 48 && keyCode <= 57) || (keyCode == 44) || (keyCode == 46) || (specialKeys.indexOf(e.keyCode) != -1 && e.charCode != e.keyCode))
var inStr = $(thisobj).val();
if (ret && (keyCode == 45) && ((thisobj.selectionStart != 0) || (inStr.indexOf('-') != -1)))
ret = false;
if (ret && (keyCode == 46) && (inStr != '' && inStr.indexOf('.') != -1) && !(Math.abs(thisobj.selectionStart - thisobj.selectionEnd) == inStr.length)) {
ret = false;
}
var dotPos = (inStr.indexOf('.') != -1) ? inStr.indexOf('.') : inStr.length;
inStr = inStr.replace(/\,/g, '');
var parts = inStr.split('.');
var maxParts = max.toString().split('.');
if (ret && (inStr != '' && (keyCode >= 48 && keyCode <= 57))) {
if ((parts[0].length >= maxParts[0].length) && ((thisobj.selectionStart - thisobj.selectionEnd) == 0)
&& (thisobj.selectionStart <= dotPos)) {
ret = false;
}
if (ret && (parts[1] != undefined && parts[1].length >= 2) && ((thisobj.selectionStart - thisobj.selectionEnd) == 0)
&& (thisobj.selectionStart > dotPos) && (thisobj.selectionStart <= dotPos + 3))
ret = false;
var firstPos = thisobj.selectionStart < thisobj.selectionEnd ? thisobj.selectionStart : thisobj.selectionEnd;
if (ret && (parts[0].length >= maxParts[0].length) && (parts[1] != undefined && parts[1].length >= 1)
&& ((dotPos - firstPos == 0 && Math.abs(thisobj.selectionStart - thisobj.selectionEnd) < 4)
|| (dotPos - firstPos == 1 && (Math.abs(thisobj.selectionStart - thisobj.selectionEnd) >= 2 && Math.abs(thisobj.selectionStart - thisobj.selectionEnd) < 4))))
ret = false;
}
if (Number(inStr) > max) {
thisobj.value = '';
ret = true;
}
if (Number(inStr) < min) {
thisobj.value = '';
ret = true;
}
// var re = new RegExp(/^\(?-?[0-9]{0,12}(\.[0-9]{0,2})?\)?$/)
// if (!re.test(inStr)) {
// thisobj.value = ""
// }
return ret
}
I found the solution! Please check the code below in case someone needs it.
function Format3DigitDecimal(e, thisobj, min, max)
{
var keyCode = e.keyCode == 0 ? e.charCode : e.keyCode
var ret = ((keyCode >= 48 && keyCode <= 57) || (keyCode == 44) || (specialKeys.indexOf(e.keyCode) != -1 && e.charCode != e.keyCode))
var inStr = $(thisobj).val()
inStr = inStr.replace(/\,/g, '')
if (ret && (inStr != '' && (keyCode >= 48 && keyCode <= 57)))
{
if ((inStr.length >= max.toString().length) && ((thisobj.selectionStart - thisobj.selectionEnd) == 0))
{
ret = false
}
}
if (ret && (inStr != '' && (keyCode >= 48 && keyCode <= 57)))
{
if ((inStr.length == 2) && ((thisobj.selectionStart - thisobj.selectionEnd) == 0))
{
ret = false
}
}
return ret
}
I would like to use .onkeydown to restrain my input field. I wrote this function, but I'd like to use it in an if condition, to check if entry keys are right or wrong.
But I don't know how form should I use in my if to call this function, because actually it's not really an Angular scope function, but a JS one...
var cpNumber = document.getElementById("cpNumber");
cpNumber.onkeydown = function(e) {
if((e.keyCode > 95 && e.keyCode < 106)
|| (e.keyCode > 47 && e.keyCode < 58)
|| ((e.keyCode > 95 && e.keyCode < 106)
|| (e.keyCorde == 65))
|| ((e.keyCode > 47 && e.keyCode < 58)
|| (e.keyCode == 65))
|| ((e.keyCode > 95 && e.keyCode < 106)
|| (e.keyCorde == 66))
|| ((e.keyCode > 47 && e.keyCode < 58)
|| (e.keyCode == 66))
|| e.keyCode == 8) {
return true;
} else {
return false;
}
};
// If condition, check if entry keys are wrong.
// I tried cpNumber.onkeydown(e), but the "e"
// seems drop from the sky, it always shows "false".
if(cpNumber.onkeydown(e) === false) {
alertPopup = $ionicPopup.alert({
title: 'Oups...',
cssClass: 'pop',
template: '<div class="center-form">This is Wrong !</div>'
});
}
<form>
<input class="input"
type="text"
id="cpNumber"
maxlength="5"
ng-model="cp"
placeholder="CP">
</form>
You need to put the calls in the blocks themselves. Here's a fiddle for you to look at:
https://jsfiddle.net/tsamzx6h/
if((e.keyCode > 95 && e.keyCode < 106)
|| (e.keyCode > 47 && e.keyCode < 58)
|| ((e.keyCode > 95 && e.keyCode < 106)
|| (e.keyCorde == 65))
|| ((e.keyCode > 47 && e.keyCode < 58)
|| (e.keyCode == 65))
|| ((e.keyCode > 95 && e.keyCode < 106)
|| (e.keyCorde == 66))
|| ((e.keyCode > 47 && e.keyCode < 58)
|| (e.keyCode == 66))
|| e.keyCode == 8)
{
alert("Good!");
}
else
{
alert("Wrong");
}
Event cannot be called this way. For making your program functional you can add a function in your else block and call it and do whatever you want.
PLUS you can also pass your event to function. So that will serve as an added advantage.
HTML:
<form><input class="input" type="text" id="cpNumber" maxlength="5" ng-model="cp" placeholder="CP"></form>
Script::
ar cpNumber = document.getElementById("cpNumber");
cpNumber.onkeydown = function(e) {
if((e.keyCode > 95 && e.keyCode < 106)
|| (e.keyCode > 47 && e.keyCode < 58)
|| ((e.keyCode > 95 && e.keyCode < 106)
|| (e.keyCorde == 65))
|| ((e.keyCode > 47 && e.keyCode < 58)
|| (e.keyCode == 65))
|| ((e.keyCode > 95 && e.keyCode < 106)
|| (e.keyCorde == 66))
|| ((e.keyCode > 47 && e.keyCode < 58)
|| (e.keyCode == 66))
|| e.keyCode == 8)
{
return true;
}
else
{
notAllowed(e);
}
};
// If condition, check if entry keys are wrong. I tried cpNumber.onkeydown(e), but the "e" seems drop from the sky, it always shows "false".
function notAllowed (ev) {
alertPopup = $ionicPopup.alert({
title: 'Oups...',
cssClass: 'pop',
template: '<div class="center-form">This is Wrong !</div>'
});
}
Hi everyone I'm making Tic-Tac-Toe Game for school. But when al boxes are checked i need the program to stop and say: you win, you lose, or draw.
But is doesn't. when you lose or win before al 9 boxes are checked it says you won or lose.
I also get this error when all boxes are checked:
Uncaught RangeError: Maximum call stack size exceeded
Code:
var button = [];
for (var i = 1; i < 10; i++) button[i] = document.getElementById('canvas'+i);
var ctx = [];
for (var i = 1; i < 10; i++) ctx[i] = button[i].getContext('2d');
var bDisabled= [];
for (var i = 1; i < 10; i++) bDisabled[i] = false;
var isResult = false;
var content = [];
function loop (x)
{
if(!bDisabled[x])
{
bDisabled[x] = true;
button[x].style.opacity = 0.7;
content[x] = 'x';
button[x].style.webkitTransform="rotatey(180deg)";
{
ctx[x].lineWidth=3;
ctx[x].beginPath( );
ctx[x].moveTo(10,10);
ctx[x].lineTo(40,40);
ctx[x].moveTo(40,10);
ctx[x].lineTo(10,40);
ctx[x].stroke();
ctx[x].closePath();
computerTurn();
}
setTimeout(checkWinner, 1000);
}
}
function computerTurn()
{
var r = Math.random();
if (r < 0.1 && !bDisabled[1]) draw0Steps(1);
else if (r < 0.2 && !bDisabled[2]) draw0Steps(2);
else if (r < 0.3 && !bDisabled[3]) draw0Steps(3);
else if (r < 0.4 && !bDisabled[4]) draw0Steps(4);
else if (r < 0.5 && !bDisabled[5]) draw0Steps(5);
else if (r < 0.6 && !bDisabled[6]) draw0Steps(6);
else if (r < 0.7 && !bDisabled[7]) draw0Steps(7);
else if (r < 0.8 && !bDisabled[8]) draw0Steps(8);
else if (r < 1 && !bDisabled[9]) draw0Steps(9);
else computerTurn();
}
function draw0Steps(x)
{
bDisabled[x]=true;
button[x].style.opacity=0.7;
content[x]='0';
button[x].style.webkitTransform="rotateX(180deg)";
setTimeout(function()
{
ctx[x].beginPath();
ctx[x].lineWidth=3;
ctx[x].arc(25,25,17,0,Math.PI*2,false);
ctx[x].stroke();
ctx[x].closePath();
}, 300);
}
function checkWinner()
{
if(!isResult)
{
if (content[1] == 'x' && content[2] == 'x' && content[3] == 'x') s howWinner('Je hebt gewonnen!');
else if (content[4] == 'x' && content[5] == 'x' && content[6] == 'x') showWinner('Je hebt gewonnen!');
else if (content[7] == 'x' && content[8] == 'x' && content[9] == 'x') showWinner('Je hebt gewonnen!');
else if (content[1] == 'x' && content[4] == 'x' && content[7] == 'x') showWinner('Je hebt gewonnen!');
else if (content[2] == 'x' && content[5] == 'x' && content[8] == 'x') showWinner('Je hebt gewonnen!');
else if (content[3] == 'x' && content[6] == 'x' && content[9] == 'x') showWinner('Je hebt gewonnen!');
else if (content[1] == 'x' && content[5] == 'x' && content[9] == 'x') showWinner('Je hebt gewonnen!');
else if (content[3] == 'x' && content[5] == 'x' && content[7] == 'x') showWinner('Je hebt gewonnen!');
else if (content[1] == '0' && content[2] == '0' && content[3] == '0') showWinner('Je hebt verloren!');
else if (content[4] == '0' && content[5] == '0' && content[6] == '0') showWinner('Je hebt verloren!');
else if (content[7] == '0' && content[8] == '0' && content[9] == '0') showWinner('Je hebt verloren!');
else if (content[1] == '0' && content[4] == '0' && content[7] == '0') showWinner('Je hebt verloren!');
else if (content[2] == '0' && content[5] == '0' && content[8] == '0') showWinner('Je hebt verloren!');
else if (content[3] == '0' && content[6] == '0' && content[9] == '0') showWinner('Je hebt verloren!');
else if (content[1] == '0' && content[5] == '0' && content[9] == '0') showWinner('Je hebt verloren!');
else if (content[3] == '0' && content[5] == '0' && content[7] == '0') showWinner('Je hebt verloren!');
else if(
(content[1]=='x' || content[1]=='0')&&
(content[2]=='x' || content[2]=='0')&&
(content[3]=='x' || content[3]=='0')&&
(content[4]=='x' || content[4]=='0')&&
(content[5]=='x' || content[5]=='0')&&
(content[6]=='x' || content[6]=='0')&&
(content[7]=='x' || content[7]=='0')&&
(content[8]=='x' || content[8]=='0')&&
(content[9]=='x' || content[9]=='0')
)
showWinner("Gelijkspel. Speel opnieuw!");
}
}
function showWinner(x)
{
alert(x);
isResult=true;
}
I have a textbox that I want it to allow typing numbers from 0.00 to 24.00 only.
<asp:TextBox ID = "txtHours" runat = "Server"
onkeydown="limit(this,event);"
onkeypress="return validateFloatKeyPress(this,event);"
MaxLength="5" Width = "40" text = '<%#showData(Container.DataItem, "Hours")%>'/>
I tried using Javascript in onkeypress and onkeydown
It's still allowing typing numbers like 25,26,25.01... etc
I want it not to even allow typing 5,6,7...etc after 2 is typed.
function validateFloatKeyPress(el, evt) {
var charCode = (evt.which) ? evt.which : event.keyCode;
var number = el.value.split('.');
var numberbfr = el.value.split('.')[0];
if (charCode != 46 && charCode > 31 && (charCode < 48 || charCode > 57)) {
return false;
}
if (number.length > 1 && charCode == 46) {
return false;
}
if (numberbfr.length > 1) {
return false;
}
var caratPos = getSelectionStart(el);
var dotPos = el.value.indexOf(".");
if (caratPos > dotPos && dotPos > -1 && (number[1].length > 1)) {
return false;
}
return true;
}
function getSelectionStart(o) {
if (o.createTextRange) {
var r = document.selection.createRange().duplicate()
r.moveEnd('character', o.value.length)
if (r.text == '') return o.value.length
return o.value.lastIndexOf(r.text)
} else return o.selectionStart
}
function limit(el, evt) {
if (parseInt(el.value.charAt(0)) > 2 || (parseInt(el.value.charAt(0)) = 2 && parseInt(el.value.charAt(1)) > 4)) {
return false;
}
}
Try this.Hope this solution will help you.Copy and paste below code.'stack' is the id of the textbox.
function checkOnlyZeroTo24(evt, el) {
var charCode = (evt.which) ? evt.which : event.keyCode
if (el.value == '' && !(charCode > 31 && (charCode < 48 || charCode > 57))) {
return true;
}
else if (el.value != '') {
if (el.value.charAt(0) < 3 && charCode == 46 && el.value.length == 1 && el.value.indexOf('.') == -1) {
document.getElementById('stack').setAttribute('maxlength', 4);
return true;
}
else if (el.value.charAt(0) < 3 && !(charCode > 31 && (charCode < 48 || charCode > 57)) && el.value.length == 1) {
document.getElementById('stack').setAttribute('maxlength', 5);
if (el.value.charAt(0) == 2 && (charCode < 48 || charCode > 52))
return false;
else
return true;
}
else if (el.value <= 24 && el.value >= 10 && charCode == 46 && el.value.indexOf('.') == -1) {
document.getElementById('stack').setAttribute('maxlength', 5);
return true;
}
else if (el.value.substr(0, el.value.indexOf('.')) <= 24 && el.value.substr(0, el.value.indexOf('.')) >= 10 && el.value.charAt(2) == '.' && !(charCode > 31 && (charCode < 48 || charCode > 57))) {
if (el.value.substr(0, el.value.indexOf('.')) == 24 && !(charCode == 48))
return false;
else
return true;
}
else if (el.value.charAt(0) < 3 && !(charCode > 31 && (charCode < 48 || charCode > 57)) && el.value.charAt(1) == '.') {
document.getElementById('stack').setAttribute('maxlength', 4);
return true;
}
else if ((el.value.charAt(0) >= 3 && charCode == 46 && el.value.indexOf('.') == -1) || (el.value.charAt(1) == '.' && !(charCode > 31 && (charCode < 48 || charCode > 57)))) {
document.getElementById('stack').setAttribute('maxlength', 4);
return true;
}
}
return false;
}
Asp:TextBox
<asp:TextBox ID = "stack" runat = "server" onkeypress="return checkOnlyZeroTo24(event,this);"> </asp:TextBox>
I have a problem restricting a text box to only numeric values. I used normal methods but it works only in windows, not working in ipod and it allows a user to enter strings and special characters. , if you know how to restrict this on iOS pls help ,
check it....
if ( event.keyCode == 46 || event.keyCode == 8 || event.keyCode == 9 || event.keyCode == 27 || event.keyCode == 13 || event.keyCode == 116 ||
(event.keyCode == 65 && event.ctrlKey === true) ||
((event.keyCode >= 35 && event.keyCode <= 45) || event.keyCode == 190 || event.keyCode == 100 || event.keyCode == 110)) {
if ((event.keyCode == 190 || event.keyCode == 100 || event.keyCode == 110) && $(this).val().indexOf('.') != -1) {
event.preventDefault();
}
else {return;}
}
else {
// Ensure that it is a number and stop the keypress
if ((event.keyCode >= 219 && event.keyCode <= 222) || (event.keyCode >= 106 && event.keyCode <= 109) || event.keyCode == 111
|| event.keyCode == 32 || event.keyCode == 59 || (event.keyCode >= 186 && event.keyCode <= 189) || event.keyCode == 191 || event.keyCode == 192 ||
event.shiftKey || (event.keyCode < 48 || event.keyCode > 57) && (event.keyCode < 96 || (event.keyCode > 105 && event.keycode < 190 )) ){
/*
if (checker.apple) {
// alert('Hh');
alert(event.keyCode);
//$.browser.apple=true;
event.shiftKey || (event.keyCode <= 48 || event.keyCode >= 57) && (event.keyCode < 96 || (event.keyCode > 105 && event.keycode < 190 ))
event.preventDefault();
}*/
//alert(event.keyCode);
/*event.preventDefault();
}
}
Limit the user to only type In Numbers:
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
if ([string length] == 0 && range.length > 0)
{
textField.text = [textField.text stringByReplacingCharactersInRange:range withString:string];
return NO;
}
NSCharacterSet *nonNumberSet = [[NSCharacterSet characterSetWithCharactersInString:#"0123456789"] invertedSet];
if ([string stringByTrimmingCharactersInSet:nonNumberSet].length > 0)return YES;
return NO;
}
You can use onkeypress() when user presses any button and fire checkAlpha() function.
and use following code to detect whether it is a number or a alphabet
function checkAlpha() {
x = event.charCode;
if (( x >= 65 && x <=90) || (x >= 97 && x <=122))
{
alert("Yes, it is alphabet");
}
else
{
alert("Sorry, only alphabet allowed");
event.preventDefault();
}
}
works fine latest android and desktop please confirm on apple devices and let me know.
please follow this code for enter only numeric value in text box. make sure for these DELEGATE methods
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
char *x = (char*)[string UTF8String];
//if(DEBUG_MODE) NSLog(#"char index is %i",x[0]);
if([string isEqualToString:#"0"] || [string isEqualToString:#"1"] || [string isEqualToString:#"2"] || [string isEqualToString:#"3"] || [string isEqualToString:#"4"] || [string isEqualToString:#"5"] || [string isEqualToString:#"6"] || [string isEqualToString:#"7"] || [string isEqualToString:#"8"] || [string isEqualToString:#"9"] || x[0]==0 ) {
NSUInteger newLength = [textField.text length] + [string length] - range.length;
return (newLength > 6) ? NO : YES;
} else {
return NO;
}
}