jushiro Posted March 10, 2012 Share Posted March 10, 2012 Hi, Im making a form that contains 3 textboxes.. now i want my textboxes to contain only letters.. i used is_numeric for the validation but when i put' like.. "JUSHIRO1" my code will still accept it. can someone help me make a code that will validate my textbox to only accept letters. and one more.. when the user input in the textbox with a number a popup box will appear. Quote Link to comment https://forums.phpfreaks.com/topic/258633-validation-help/ Share on other sites More sharing options...
Allenph9 Posted March 10, 2012 Share Posted March 10, 2012 I don't think what your trying to do is possible in php. but I might be wrong...you could to errors though like this... <?php $invalid_character_test1 = substr_count($_POST['text_box'], '1'); $invalid_character_test2 = substr_count($_POST['text_box'], '2'); $invalid_character_test3 = substr_count($_POST['text_box'], '3'); $invalid_character_test4 = substr_count($_POST['text_box'], '4'); $invalid_character_test5 = substr_count($_POST['text_box'], '5'); $invalid_character_test6 = substr_count($_POST['text_box'], '6'); $invalid_character_test7 = substr_count($_POST['text_box'], '7'); $invalid_character_test8 = substr_count($_POST['text_box'], '8'); $invalid_character_test9 = substr_count($_POST['text_box'], '9'); $invalid_character_test10 = substr_count($_POST['text_box'], '0'); if (($invalid_character_test1 == "0") && ($invalid_character_test2 == "0") && ($invalid_character_test3 == "0") && ($invalid_character_test4 == "0") && ($invalid_character_test5 == "0") && ($invalid_character_test6 == "0") && ($invalid_character_test7 == "0") && ($invalid_character_test8 == "0") && ($invalid_character_test9 == "0") && ($invalid_character_test10 == "0") ){ $error = 'All valid characters!'; } else { $error = 'Contains invalid characters!'; } ?> <form action="test_box_example.php" method="post" name='text_box_example"> <input type="text" name="text_box" value="Enter value here!"> <input type="submit" name="submit_text_box" value="Submit"><?php if (isset($_POST['submit_text_box'])) { echo $error; } ?> </form> Now I probably should have used an array but that will get the job done...What that does is gets what you entered into the field sends it to this page(assuming the page is named text_box_example.php) then each test counts how many times the number it is testing was in that test box. Then that if else statement says if all of those tests come back 0 (there were no numbers in the box) the error variable equals All valid characters! but if all those are not equal to zero then there must be a number in your text box so the echo equals Contains invalid characters! then if you press the button it prints out the error right next to the submit button. Quote Link to comment https://forums.phpfreaks.com/topic/258633-validation-help/#findComment-1325777 Share on other sites More sharing options...
Pikachu2000 Posted March 10, 2012 Share Posted March 10, 2012 Ummmm . . . . Yeah. ctype_alpha Quote Link to comment https://forums.phpfreaks.com/topic/258633-validation-help/#findComment-1325838 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.