Jump to content

VALIDATION HELP


jushiro

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/258633-validation-help/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/258633-validation-help/#findComment-1325777
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.