How to validate emails?
Would you please show an example with an error message?
Documentation does not give enough details.
It seems there is nothing like v-if="!$v.user.email.email"
Following code does not work either
validations: {
user: {
email: {
required,
email: email(),
},
}
}
Actualy, I was wrong and there was something like v-if="!$v.user.email.email"
You do not need any details for email validator.
All you need is
email: {
email,
},
If you had any Vetur errors just uninstall Vetur and reinstall it.
Vue.use(window.vuelidate.default)
const { email } = window.validators
new Vue({
el: "#app",
data: {
user: {
email: ""
}
},
validations: {
user:{
email: {
email
}
}
},
methods: {
status(validation) {
return {
error: validation.$error,
dirty: validation.$dirty
}
}
}
})
input {
border: 1px solid silver;
border-radius: 4px;
background: white;
padding: 5px 10px;
}
.dirty {
border-color: #5A5;
background: #EFE;
}
.error {
border-color: red;
background: #FDD;
}
<script src="https://cdn.jsdelivr.net/combine/npm/vuelidate#0.7.5/dist/validators.min.js,npm/vuelidate#0.7.5/dist/vuelidate.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="app">
<input v-model="$v.user.email.$model" :class="status($v.user.email)">
<div class="error" v-if="!$v.user.email.email">this must be an email</div>
<pre>{{ $v }}</pre>
</div>
Answer https://stackoverflow.com/a/61359412/11993949 shows off how to use on blur functionality too
you can use this regex validation pattern to validate your email.
[a-zA-Z0-9]+#[a-z]+\.[a-z]{2,3}
If you are getting as json format you can try this
[a-zA-Z0-9]+#[a-z]+\\.[a-z]{2,}
Related
We are creating an application in vue
Does anyone know how to format text partially
like this?
You cannot create hard constraints from ellipses, but this functional may be procedural.
If you know what words you need to style, try like following snippet:
new Vue({
el: "#demo",
data() {
return {
messages: { unstyled: 'no styling!', styled: 'platformy dobrix del!' },
};
},
methods: {
words(string) {
return string.split(/\s+/);
},
isMarked(string) {
return /dobrix/i.test(string);
},
},
})
.marked {
color: red;
position:relative;
}
.marked::before {
content: "";
background: turquoise;
position: absolute;
height: 20px;
width: 92%;
top: 20px;
z-index: -1;
border-radius: 10px;
}
*{
font-weight: 800;
font-size: 32px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="demo">
<div class="container">
<div v-for="(value, name) in messages" :key="name">
<span v-for="(word, index) in words(value)" :key="index">
<span v-if="isMarked(word)" class="marked">{{ word }} </span>
<span v-else>{{ word }} </span>
</span>
</div>
</div>
</div>
I am using Material-UI v5 for my project. I need to style my scrollbars using the following css
body::-webkit-scrollbar {
width: 12px;
}
body::-webkit-scrollbar-track {
background: blue;
}
body::-webkit-scrollbar-thumb {
background-color: red;
border: 3px solid black;
border-radius: 10px;
}
I tried using makeStyles as following:
const useStyles = makeStyles((theme: Theme) => ({
root: {
background: theme.palette.primary.main,
'html': {
scrollbarWidth: 'thin',
scrollbarColor: theme.palette.accent.main
},
'body::-webkit-scrollbar': {
width: '12px'
},
'body::-webkit-scrollbar-track' : {
background: theme.palette.primary.main,
}
},
}));
But when I inspect the actual source css was coming as 'body::-webkit-scrollbar' : Object[object].
I am stuck on how to add global css like this in material-ui and what is the best way to do this.
Also please let me know incase I am doing anything wrong here. Thanks in advance.
This is my button used in html where I am having an onClick attribute for the button to open the link mentioned there , where the button link is not working.
I am sending this email through nodemailer using node.js
<div style="text-align: center; ">
<button style="border-radius: 5px;
text-align: center;
padding: 10px;
font-size: medium;
border: none;
color: aliceblue;
background-color: blue;"
onClick="window.open('http://localhost:3000/tournaments');">
Register
</button>
</div>
this is function which calls uses the HTML template concept to use the above html
var transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: 'test#gmail.com',
pass: 'test'
}
});
const email = new Email({
transport: transporter,
send: true,
preview: false,
views: {
options: {
extension: 'ejs'
}
},
});
email.send({
template:path.join(__dirname,'./templates/emailCampaign'),
message: {
from: 'test#gmail.com',
to: 'test#gmail.com,test#srmist.edu.in',
},
locals: {
tournament_name:tournament_name,
date:(new Date(date)).toLocaleDateString(),
time:(new Date(date)).toLocaleTimeString(),
fee:registration_fee,
sections:sections,
description:description
},
}).then(() => console.log('email has been sent!'));
I have Vue single-file component which displays a product's details (well its meant to anyway). All my data seems to be loading fine from a Vuex store. This is my Product.vue page:
<template>
<div class="page-content">
{{Product}} <!-- this works and shows JSON on the page -->
{{Product.ProductTitle}} <!-- this shows nothing at all -->
</div>
</template>
<script>
import {mapGetters} from 'vuex';
export default {
name: "Product",
computed:
{
...mapGetters({
Product: 'getProduct',
})
},
serverPrefetch() {
return this.getProduct();
},
mounted() {
if (!this.Product.length) {
this.getProduct();
}
},
methods: {
getProduct() {
return this.$store.dispatch('loadProduct', {ProductID: this.$route.params.ProductID})
}
}
}
</script>
The data in the computed Product variable is just this:
[ { "ProductID": 12552, "ProductTypeID": 1, "ProductStatusID": 3, "ProductTitle": "Sony PlayStation 4 Pro" }]
I cannot fathom out why {{Product}} displays the whole JSON object, but {{Product.ProductTitle}} shows nothing?
UPDATE: JSFiddle showing problem
You have an object inside array inside array e.g.: [[{}]] so you have to get the data like this: {{Product[0][0].ProductTitle}}
new Vue({
el: "#app",
data: {
Product: [
[{
"ProductID": 14896,
"ProductStatusID": 3,
"CountryID": 207,
"ProductTitle": "PS4 Pro Console + Call of Duty: Modern Warfare / Death Stranding + Metro Exodus",
"ProductItemDescription": "<p>The best PS4 Pro bundle offer!</p>"
}]
]
}
})
body {
background: #20262E;
padding: 20px;
font-family: Helvetica;
}
#app {
background: #fff;
border-radius: 4px;
padding: 20px;
transition: all 0.2s;
}
li {
margin: 8px 0;
}
h1 {
color: black
}
h2 {
color: blue;
margin-bottom: 15px;
}
del {
color: rgba(0, 0, 0, 0.3);
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="app">
<article role="article" class="">
<h1>
{{Product[0][0].ProductTitle}}
<!-- this doesn't work? -->
</h1>
<h2>
{{Product}}
</h2>
</article>
</div>
I'm facing a problem where i cannot bind :invalid css selector with my input since i have custom validation. invalid is only active with basic validator example: input type="email" so the invalid will work with example# or example#example.exmaple while my function only validates the last one (example#example.example).
Project Link
HTML FILE
<input class="custom-input" type="email" [(ngModel)]='Email' name="email" placeholder="Email" formControlName="emailTxt">
<div class="err>
this is an error
</div>
TypeScript File
this.signUpForm = this._fb.group({
emailTxt: [null, Validators.compose([
Validators.required
])]
}, {
validators: [
EmailValidation('emailTxt'),
]
});
Form Validation Function
export function EmailValidation(controlName: string) {
return (formGroup: FormGroup) => {
const control = formGroup.controls[controlName];
if (control.errors && !control.errors.invalidEmail) {
return;
}
if (control.value.trim().match(/^([a-zA-Z0-9_\-\.]+)#((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{1,5}|[0-9]{1,3})(\]?)$/) == null) {
control.setErrors({ invalidEmail: true });
}
else {
control.setErrors(null);
}
}
}
CSS File
.custom-input:invalid{
& ~ .err {
max-height: 200px;
padding: 0 18px 10px 20px;
color: red;
}
}
i expect the invalid selector should to be triggered with every control.setErrors() function
Add below CSS code in your project, that's definitely works
input.ng-dirty.ng-invalid {
border: 1px solid red;
}
This will work Definitely ☺ add to ur css file
input.ng-invalid.ng-touched, select.ng-invalid.ng-touched {
border: 1px solid red !important;
}