Allow Only String and Numbers Using PHP

To Allow Only String and Numbers Using PHP, we use PHP in-built functions. We do it with textbox input. Where the user gives some input on the textbox then using PHP inbuilt function we validate the staring or number using PHP.

Allow Only String and Numbers Using PHP
Allow Only String and Numbers Using PHP

Here are 2 thing we discuss about,

  • Allow only characters in textbox using PHP.
  • Allow only numbers in textbox using PHP.

Allow only characters in textbox using PHP

ctype_alpha: ctype_alpha() is PHP inbuilt function that can validate the user input is a string or any character or not. This also takes the spaces between characters as non-character.

Example:

Here we use PHP session to maintain the textbox value after page reload.

Output:

Allow only characters in textbox using PHP
Allow only characters in textbox using PHP

Allow only numbers in textbox using PHP

ctype_digit: ctype_digit() is also a PHP inbuilt function which validates only digit or numbers entered by the user. This is also doesn’t take any spaces on the textbox.

Example:

On the above code we also manage the value after page is reloaded by using PHP session.

Output:

Allow only numbers in textbox using PHP
Allow only numbers in textbox using PHP

How to Test

Copy complete code and create a PHP file then paste the code.

You can also use localhost to test. You can check the out also on above.

If you want to know more about those function, you can check on PHP official site here: https://www.php.net/manual/en/ref.ctype.php

Also Check:

Happy Coding..!

Was this article helpful?
YesNo
My name is Bikash Kr. Panda. I own and operate PHPCODER.TECH, my native place in Odisha. I am a Web Programmer by profession and working on more than 50 projects to date. My passion is working on the web-based project using PHP and relate to all CMS and frameworks which is based on PHP.
Posts created 175

2 thoughts on “Allow Only String and Numbers Using PHP

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Posts

Begin typing your search term above and press enter to search. Press ESC to cancel.

Back To Top
mariobet - supertotobet - escort -

takip7.com

- milanobet giriş - gizabet giriş -
perabet giriş
- betkanyon giriş -

jojobet giriş

We are now accepting guest posting and creation of back-links.
This is default text for notification bar