austine_power007 Posted December 7, 2006 Share Posted December 7, 2006 I have a form and I want to be sure that user give only integer value or it will give a error message.I think i can use java script does anyone have that ?? help me :-[ Link to comment https://forums.phpfreaks.com/topic/29767-check-integer-or-not/ Share on other sites More sharing options...
mansuang Posted December 7, 2006 Share Posted December 7, 2006 use regular expressionlink for javascript [url=http://www.phpfreaks.com/javascript_manual/page/regexp.htm]http://www.phpfreaks.com/javascript_manual/page/regexp.htm[/url]link for php [url=http://www.phpfreaks.com/phpmanual/page/ref.regex.html]http://www.phpfreaks.com/phpmanual/page/ref.regex.html[/url] Link to comment https://forums.phpfreaks.com/topic/29767-check-integer-or-not/#findComment-136681 Share on other sites More sharing options...
austine_power007 Posted December 7, 2006 Author Share Posted December 7, 2006 [quote author=mansuang link=topic=117681.msg480292#msg480292 date=1165466668]use regular expressionlink for javascript [url=http://www.phpfreaks.com/javascript_manual/page/regexp.htm]http://www.phpfreaks.com/javascript_manual/page/regexp.htm[/url]link for php [url=http://www.phpfreaks.com/phpmanual/page/ref.regex.html]http://www.phpfreaks.com/phpmanual/page/ref.regex.html[/url][/quote]I am new in php and tht don't have much example..........so please send me some easy code so that will be easy for me......sorryy i m NUT Link to comment https://forums.phpfreaks.com/topic/29767-check-integer-or-not/#findComment-136712 Share on other sites More sharing options...
bljepp69 Posted December 7, 2006 Share Posted December 7, 2006 For checking the form submission using PHP you could try something like:[code]if (!preg_match('/[^0-9]+/',$FORMVARIABLE)) { //error code goes here}else { //process code here}[/code]I haven't tested this, but it should reject everything that's not an integer. You'll just have to fill in the $FORMVARIABLE with your actual variable and then write the error and process code. Link to comment https://forums.phpfreaks.com/topic/29767-check-integer-or-not/#findComment-136717 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.