Hello
I would like to know how to validate user input in terms of:
Length of input
Input format (I would like to restrict to hex)
and any other useful links regarding the matter
thanks
Hello
I would like to know how to validate user input in terms of:
Length of input
Input format (I would like to restrict to hex)
and any other useful links regarding the matter
thanks
If i were you i would create my own function(which maybe would use manufactured functions) in order to validate input.For exampe for length of input,in case we have a string,i would pass the string as an argument at a function,which would check the length with strlen and then my function would return true or false.
Ok ill look at that:
I'm basically gonna say
Please insert start address (in hex):
Please insert end address (in hex):
If it isn't hex or valid (within the variable hex) then display error
I think I can figure it out once I know how to check if data inputted is hex - how would I do this?
Last edited by mrapoc; 08-04-2012 at 08:17 AM.
You could check if the string contains what a hex should contain (A-F, 0-9).InStr() is useful to see if a specific character exists in a string.
(these i wrote to you after googling )
Is there a specific reason you only want to accept hexadecimal numbers? In the end it should be the value that counts not what base is used, right. I would consider fgets() to get a string to a buffer, then strtol to get the number from the string. strtol accepts hexadecimal, octal and decimal numbers and can also detect if the input is not a number. Once you have your values you can also check if the range makes sense, if that is necessary.
Well I suppose as long as when its converted to hex it makes sense...
In that case...I only need one check and thats to ensure that the value is within the range
The user could input 255, which is FF - I see what you mean