Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > PHP How-To
|
PHP How-To Post your "How do I do this with PHP?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 13th, 2008, 02:17 PM
Registered User
 
Join Date: Oct 2008
Posts: 5
Thanks: 3
Thanked 0 Times in 0 Posts
Default pre checking of submitted data

hi everyone..
In my project,i have a html form with several fields.
I want that no one could enter anything except digits in those fields.if someone enters any character or any other thing it will generate error.
Is there any php function by which i can check the submitted data from the form,for the presence of any character,so that i can generate error for that to the user.

thank u for ur support..

 
Old October 15th, 2008, 11:24 PM
Friend of Wrox
 
Join Date: Oct 2007
Posts: 130
Thanks: 0
Thanked 3 Times in 3 Posts
Send a message via AIM to urtrivedi
Default

You need not to use php. You can do it at client side using javascript.

<html>
<script language='javascript'>

isInteger  = /^[0-9\-]+$/;

function checkdata()
{
    if (!isInteger  (document.frm.txt1.value))
    {
        alert('Enter valid number');
        document.frm.txt1.focus();
        return false;
    }
    if (!isInteger  (document.frm.txt2.value))
    {
        alert('Enter valid number');
        document.frm.txt2.focus();
        return false;
    }

    document.frm.submit();
}
</script>
<body>

<form name='frm' id='frm' method='post' action ='somescript.php'>

<input type=text name='txt1' >
<input type=text name='txt2' >
<input type=button name=btn1 onClick='javascript:checkdata();'>

</form>

</body>

</html>

urt

Help yourself by helping someone.





Similar Threads
Thread Thread Starter Forum Replies Last Post
data entry pre-fix value mateenmohd Access 5 February 17th, 2008 07:52 AM
Data reader checking.... janees ASP.NET 1.0 and 1.1 Professional 1 March 11th, 2007 06:09 AM
Checking Data Before Inserting rit01 ASP.NET 2.0 Professional 17 February 28th, 2006 09:17 AM
Validating submitted data leno Beginning PHP 6 January 5th, 2005 06:18 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.