How to use only email validation by pattern in AngularJS 1.2? - javascript

In other words I want to disable angular email validation and use only ng-pattern validation. How I can do it?
Plunker example (me&#example.com need to be valid email address)

replace the type from email to text,
<input type="email" .....>
by
<input type="text" .....>

Set email to text and regex to this.
<input type="text" name="input" ng-model="text" ng-pattern='/^[a-z]+[a-z0-9._]+#[a-z]+\.[a-z.]{2,5}$/' required>

In my case I decide to use default AngularJS email validation till update to 1.3 version or higher. In higher version I haven't this bug.

Related

Regex match exact word

I have two inputs for registration part of my project:
password <input type="password" ng-model="userData.password">
confirm password <input type="password" ng-model="userData.confirmPassword">
I am using ng-pattern to check if userData.confirmPassword is exactly same as userData.password using this:
<input ng-pattern="^userData.password$" ng-model="userData.confirmPassword">
The problem with the current code is that:
If password is stackoverflow and confirm passwors is 123stackoverflow123, the regex will still match and will return true for my form.
What regex can I place to match only if the whole text is matching?
The following change is recommended as per the documentaion:
<input ng-pattern="{{userData.password}}" ng-model="userData.confirmPassword">

Passwords validation using jquery form validation jquery.form-validator.js

I am using following code where I need to match the passwords inside a form. It doesn't work on most of helps provided on here and other websites. I could have missed something that I am unable to trace. Please help me with this.
HTML
<form id="user_form" class='has-validation-callback'>
<input type="password" name="pass_confirmation" class="form-control" data-validation="length" data-validation-length="min6">
<input type="password" name="pass" id="pass" class="form-control" data-validation-confirm="confirmation" data-validation-help="Please give us some more information">
</form>
JavaScript
$.validate({
modules : 'security',
form : '#user_form',
onError : function() {
alert('Sorry! Please complete the form fields.');
}
});
Link to library
http://cdnjs.cloudflare.com/ajax/libs/jquery-form-validator/2.3.19/jquery.form-validator.js
Please refer password confirmation
This validator can be used to validate that the values of two inputs are the same. The first input should have a name suffixed with _confirmation and the second should have the same name but without the suffix.
<input type="password" name="pass_confirmation" class="form-control" data-validation="length" data-validation-length="min6">
<input type="password" name="pass" id="pass" class="form-control" data-validation="confirmation" data-validation-help="Please give us some more information">
for the second input change attribute data-validation-confirm="confirmation" to data-validation="confirmation" it will work.
Working fiddle
Try using a newer version of the library as it seems there may be a bug.
I was using the same version you had listed and received the same error. https://github.com/victorjonsson/jQuery-Form-Validator/issues/479

ng-show="frm.Email.$error.email " doesn't show the error of invalid email

I am trying to create a login form in mvc-asp.net with angularjs validation ,
here is my code :
<span style="color:red" ng-show="frm.Email.$dirty || frm.Email.$invalid">
<span ng-show="frm.Email.$error.required">ایمیل را وارد کنید</span>
<span ng-show="frm.Email.$error.email">ایمیل وارد شده نامعتبر است</span>
</span>
when i leave the textbox empty the error is appeared frm.Email.$error.required but when i enter an invalid email mike.com the error ofng-show="frm.Email.$error.email doesn't appear.why?
It seems you are using
<input type="text">.
For email, you should use
<input type="email">.
To validate email address, Angular use HTML5 valid and invalid controls.
You have to use
<input type="email">
instead of
<input type="text">
or text with a ng-pattern which contains the pattern you need in that case.
P.S: dont forget to have <form novalidate> in your form to avoid the HTML5 validations and apply your Angular Validations
I think you forgot to provide ng-pattern attribute for the input element
"form.mail.$error.email" //**form-name.input-name.$error.email**
<form ng-app="" name="form">
<div>
<label>e-mail:</label><input type="email" id="mail"name="mail" ng-model="mail">
<p><div ng-show="form.mail.$error.email">Enter the valid mail id</div></p>
</div>
In ng-show i have checked the email in validation..form refers to name of the form tag , mail refers to name of input type email $error refers to check the error and email refers to type of the email..

how to only allow text in parsely.js validation

I am using the nifty parsley js As you can see in the documentation
there is only data-parsley-type="alphanum" which allows numbers and letters. I am trying to create fields that ONLY allow letters.
Anyone know how to do this?
You could use a pattern:
data-parsley-pattern="^[a-zA-Z]+$"
You can use such input validator, in order to obtain an only letter field.
<input type="text" class="form-control" required data-parsley-pattern="^[a-zA-Z ]+$" placeholder="Type something" />

How to show single quotes in string in javascript code?

I am generation dynamic content using javascript and inside that content a part will be like
onfocus="if(this.value=='Enter Email Address'){this.value='';}" onblur="if(this.value=='') {this.value='Enter Email Address';}" value="Enter Email Address"
I want above code but after generation of the content but all the single quotes are not showing properly. Please help me out. Thanks
If you're working in HTML 5 with input element, i would suggest you to look at the placeholder attribute, as this is exactly what you are needing for. No javascript needed.
<input type="text" placeholder="Enter Email Address" />
use Escape character \
'\\'Enter Email\\''
try this
'\'Text\''
or
"'Text'"
try something like this , Remove backslash from double quotes,FIDDLE
<input type="text" onfocus="if(this.value=='Enter Email Address'){this.value='';}" onblur="if(this.value=='') {this.value='Enter Email Address';}" value="Enter Email Address">

Categories