I am new to wordpress and php, I’m using contact form 7 in my wordpress website. In that I need to validate the email address, block all free domains like gmail, yahoo,etc., I need to validate Indian phone number with country code.
I had 4 types of contact form but I need this custom validation for only one form. I googled and found this but it is not working. Someone please help me with this issue.
Thanks.
Add following code to your theme‘s
functions.php
file.You can achieve your desired result by the above code.
NOTE: I have validated only Email.You can do same for contact like I did for Email.
Answer for second problem:
Now as you have mentioned that you want it for only one form then you can do something like this:
Then, use a tag like this inside the form:
If you want to understand the tag syntax then go through this page.
Hope it helps you.
Best answer found here. Define a function to check for the domains.
Then hook into it
I’m checking for field names
company-email
you can change this for your caseUse the following code, I’ve altered a bit, that will do the work,
Paste the above code in text.php file inside contact form 7 plugin module.
Solution :
1) Open your contact form 7 plugin text.php file,
2) In your browser/Text Editor, Press Ctrl+F, then search for the below code.
3) Replace the above code with
Note: I
4) Update your contact form 7 text.php file.
5) To block free domains. Use the below code in Edit contact form,
6) Enjoy using wordpress !!!!
Thanks @Palani Kamaraj. But what if I want to block all the sub-domain’s of free hosting providers, like; google.co.** , yahoo.co.**, etc ? My array values, goes on increasing.
I found another solution for this, and exploded the array twice first with ‘@’ then later again with ‘.’ So in your code above for step 3, the code you can replace with below
Thank You 🙂 Happy Coding 🙂