0

I need to validate a text box.user should not enter any mail id and also no numbers lengthier than 10..Please give your suggestions

kcak11
  • 832
  • 7
  • 19
  • 7
    Try something yourself first. – user4035 Jan 30 '14 at 06:56
  • 1
    read about regular experssions – user2727841 Jan 30 '14 at 06:57
  • 1
    What should be allowed? Normal text? Numbers and text mixed? _Invalid_ email adresses (i.e. simple text containing `@`)? – knittl Jan 30 '14 at 06:58
  • @knittl-yes but with spaces – user3251939 Jan 30 '14 at 06:59
  • In order to answer this question, you have to specify EXACTLY what is and isn't allowed in the textbox. So far, the ONLY thing you've really said is that it can't be a number longer than 10 digits. "not enter any mail id" is a nebulous statement - you have to be a lot more detailed about what that means. Do you mean that it can't be any sequence of characters that could be a legal email address such as "xxx@yyy"? Provide examples of things that are allowed and things that are not. Then lastly, show us what you've tried already so we know where you got stuck. – jfriend00 Jan 30 '14 at 07:02

2 Answers2

0

As everyone else is commenting, please try to do some research before posting your question, as all of the below answers have been taken from this site's previous answers only.

Your query can be divided into two parts -

Email Validations

You can find email validation scripts already answered here and here on StackOverflow.

For PHP server-side validations, taken from here.

function validateEmail($email) {
  return (bool) stripos($email,'@');
}

All the above functions will return true if the text entered is an email. So you might probably need to check for a false condition as you do not want email addresses to be entered.

Number Validations

Similarly, the check for numbers not being entered more than 10 characters, you may use:-

  1. Simple

  2. Javascript validation can be found here

However, there are still some unhandled cases in your question - What happens when someone enters normal text but greater than 10 characters? Should this be allowed? Ideally it should as it is not an email, it is not a number greater than 10 digits?

Community
  • 1
  • 1
user489895
  • 131
  • 1
  • 10
0

<label>
Student Mobile no :
</label>
<input type="text" name="country code"  value="+91" size="2"/>
<input type="tel" name="phone" size="10"/> <br> <br>

<label>
Guardian Mobile no :
</label>
<input type="text" name="country code"  value="+91" size="2"/>
<input type="tel" name="phone" size="10"/> <br> <br>

<label for="email">Email :</label>
 <input type="email" placeholder="Enter Email" name="email" required>

Just use either maxlength for text type input attribute inside the input tag of HTML forms or use size attribute for phone type input attribute the same.

For the email validation use type = "number" attribute in the input tag of HTML forms. Please refer to the code above.