how to validate a numeric field?
I need to validate a field which is numeric. Can anyone point me in the right direction?
I am really new to programming and do not know how to go about crreating a method or furnction to validate a textbox field every time a user enters data into it.
Thanks in advance,
Lee
mhelalPosted Mar 3, 2004, 10:18 AM
private bool ValidateData(string data, DataType type) { if(type == DataType.Number) { for(int i =0; i< data.Length;i++) { int charUn = Convert.ToInt32(data[i]); if((charUn >= 48) && (charUn <= 57)) { continue; } else { return false; } } return true; } else { for(int i =0; i< data.Length;i++) { int charUn = Convert.ToInt32(data[i]); if(((charUn >= 65) && (charUn <= 90)) ||((charUn >= 97)&&(charUn <= 122)) ||(charUn == 32)) { continue; } else { return false; } } return true; } }
hope useful!
jose.acidrainPosted Feb 24, 2004, 4:40 AM