how to check if the inputted email has "#" on it - html

i have a text field for email which is set to required, i want it to show a text that you need to include "#" on your email. like how it displays "fill out this field" when you pressed the button without typing anything on the field. How can i do it? Thanks.
EXAMPLE:
<input type="text" name="email" required>

You can try to use the type in case you are using HTML5 as:
<input type="email" name="email" required>
If you are not using the HTML5 then you need to use some scripting language like Javascript to check the validity. For example in Javascript it would be like:
if(!document.getElementById("email").checkValidity())
In case of PHP it would be like
if (filter_var($email, FILTER_VALIDATE_EMAIL))

You can check it by using (since HTML5):
<input type="mail" name="email" required>
It will display a warning if format is not correct (tooltip, or red color around the field, depending on your browser.
Or you can check it on the server side, once you form is sent. For example with PHP, you can use filter_var

Use pattern attribute,
<input type="text" name="email" pattern=".*[#]+.*" />
<input type="email" name="email" required />
More details are at: http://www.w3schools.com/tags/att_input_pattern.asp

Related

Pattern attribute for Email validation is not working in html5

Using Html5 I've a view which contains an email input field.
So to validate the correct email address I am using pattern attribute for validation.
But that is not working correctly, the problem I am facing here is though I enter invalid email address as abc#gmail the validation is not working.
i tested the same regex pattern in fiddler, it is working fine there, but coming to my application it is not working correctly. Please help me out with this.
Here is my view:
<form>
<input type="email"
class="form-control"
data-val="true"
data-val-required="please enter an email address"
pattern="[a-z0-9._%+-]+#[a-z0-9.-]+.[a-z]{2,4}$"
required>
<input type="submit" />
</form>
Regex should be
[a-z0-9._%+-]+#[a-z0-9.-]+.[a-z]{2,}$
instead of
[a-z0-9._%+-]+#[a-z0-9.-]+.[a-z]{2,4}$
So the html input would be:
<input type="email"
class="form-control"
data-val="true"
data-val-required="please enter an email address"
pattern="[a-z0-9._%+-]+#[a-z0-9.-]+\.[a-z]{2,}$"
required>
NOTE: difference in regex is {2,} and {2,4}

How can I disable HTML5 form validation in Angular2 apps?

I have a form that contains an input of type email that is required. I would like to have my own custom validation on that input field in order to be able to show the error message in different languages. However, currently the input field is evaluated by the HTML5 validation.
The code looks like this:
<input [(ngModel)]="user.email" type="email" class="form-control" id="email" name="email" required placeholder="{{'Email'|translate}}">
Is it possible to disable that, so that I am able to implement my own validation?
The validation code is yet to be written.
Include tag with no validate attribute as below
<form action="Form" novalidate>
<input [(ngModel)]="user.email" type="email" class="form-control" id="email" name="email" required placeholder="{{'Email'|translate}}">
<input type="submit">
</form>

how to use ng-mask in angularjs

how to use ng-mask for validation of phone number having pattern (xxx)xxx-xxxx . I tried using "pattern" in the input html tag but not satisfied with the result
because each time when user enters the phone number, the user must type both '()' and '-',and this will make the user annoying. So suggest a way to overcome this.
<input type="tel" name="phoneno" maxlength=13 ng-model="phone.number" pattern="^(?:\(\d{3}\)|\d{3}-)\d{3}-\d{4}$" required/></div>
This should work:
<input type="text" ng-model="phone.number" name="phone" mask="(999) 999-9999" clean="true" ng-model="phone">

HTML5 email does not allow email with a period

The following email is not accepted with a period, is this a regular expression issue or some bug.
This works
abcdefg.jijklmn#abcdedghijklmnopgi.com
but the following doesn't (note uppercase letter in the email "A" and "J"), i think that is the problem
Abcdefg.Jijklmn#abcdedghijklmnopgi.com
Html element
<input type="email" class="form-control" name="email" pattern="[a-z0-9._%+-]+#[a-z0-9.-]+\.[![\[][1]][1]a-z]{2,3}$" required="" value=""/>
Error below
It's because your regex doens't allow capitals.. simply allow capitals..
[a-zA-Z0-9._%+-]+#[a-z0-9.-]+\.[![\[][1]][1]a-z]{2,3}$
Regular expressions for emails can be very difficult. However, you don't actually need to use a pattern to validate emails as type="email" does that for you. Simply remove the pattern entirely and the clients browser will validate the email for you using their in-built regex
<input type="email" class="form-control" name="email" required="true" value=""/>
I can't actually seem to get email validation to work with the pattern attribute at all, as I think it's competing with type="email".

Multiple patterns in <input>

I am trying to use multiple patterns for an input-field in HTML5.
<input type="text" pattern="\d*.{5,10}" name="plz">
My current input field does not work. Only the second pattern .{5,10} is relevant for the submit. The first attribute \d* hast no effects.
Try the below:
<input type="text" placeholder="" class="form-control" pattern="([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{4})([0-9]{1})">
and just accept AESE640526HOCCNL05...
Hope this can help you.