How to show single quotes in string in javascript code? - javascript

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">

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">

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

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.

ngTagsInput in Angular

I am using tagsInput Api in Angular
here is link
i want to add a tag on space. but it is not working.
here is my code
<tags-input ng-model="emails" placeholder="Add an Email" [add-on-space="true"]>
Also i want to add Email validator in tags . i have no idea.
Any idea how to do this ?
Thanks
Try dropping the square brackets from your attribute. e.g.:
<tags-input ng-model="emails" placeholder="Add an Email" add-on-space="true">
Square brackets are just used in their documentation to indicate the ones that are optional. In its current form, your HTML isn't valid.
To validate emails, try the "allowed-tags-pattern" attribute with regex, as below:
<tags-input ng-model="emails" placeholder="Add an Email" add-on-space="true" allowed-tags-pattern="^[a-zA-Z0-9_.+-]+#[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$">
Hope this helps.

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" />

Validation to check any email id or 10 digit numbers

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
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:-
Simple
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?
<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.

Categories