logo
Tags down

shadow

ReactJS - using onBlur to validate email field


By : tien
Date : October 14 2020, 02:21 PM
it should still fix some issue I think the right way to do so is by using internal state of the component:
code :
class EmailComponent extends React.Component {
  state = {
    validEmail: false,
    email: '',
  };

  onChange = (e) => {
    ...
    this.setState({
      email: e.target.value
    });
  }

  validateEmail = (e) => {
    const email = e.target.value;
    if (!email || invalidEmail(email)) {
      this.setState({
        validEmail: true,
      });
    } else {
      this.setState({
        validEmail: false,
      });
    }
  }

  render () {
    const { validEmail, email } = this.state;

    return (
      <TextField
        margin="dense"
        id="emailAddress"
        name="email"
        label="email"
        type="email"
        onChange={this.onChange}
        onBlur={this.validateEmail}
        value={email} //I think you should also set email as a state
        error={validEmail}
        helperText={validEmail ? 'Please enter a valid Email' : ' '}
        fullWidth
      />
    );
  }
}
class ParentComponent extends React.Component {
  state = {
    validEmail: false,
    email: '',
  };

  onChange = (e) => {
    this.setState({
      email: e.target.value
    });
  }

  validateEmail = (e) => {
    const email = e.target.value;
    if (!email || invalidEmail(email)) {
      this.setState({
        validEmail: true,
      });
    } else {
      this.setState({
        validEmail: false,
      });
    }
  }

  render () {
    const { validEmail, email } = this.state;

    return (
      <ChildComponent 
        email={email}
        validEmail={validEmail}
        onChange={this.onChange}
        validateEmail={this.validateEmail}
      />
    );
  }
}

const ChildComponent = (props) => (
  <TextField
    margin="dense"
    id="emailAddress"
    name="email"
    label="email"
    type="email"
    onChange={props.onChange}
    onBlur={props.validateEmail}
    value={props.email}
    error={props.validEmail}
    helperText={props.validEmail ? 'Please enter a valid Email' : ' '}
    fullWidth
  />
);


Share : facebook icon twitter icon

Validate phone field with javascript without using onblur


By : user2331626
Date : March 29 2020, 07:55 AM
I wish this helpful for you I have a problem that's probably simple but i cannot change the moment of the validation. , You could use the optional character after the 8th digit.
code :
$('.phone').mask('99999999Z', {translation:  {'Z': {pattern: /[0-9]/, optional: true}}});

Using an input field with onBlur and a value from state blocks input in Reactjs JSX?


By : Yetesh Chaudhary
Date : March 29 2020, 07:55 AM
I wish this help you The value attribute ties the value of the input to that state, and if the user changes the value then the state and the input value is no longer tied to each other. So React stops that from happening.
You probably want to use the defaultValue attribute instead.

Angular2 reactive form validate multiple email in single input field eg: cc in email form


By : Andre
Date : March 29 2020, 07:55 AM
I wish did fix the issue. To answer to your last comment, here is how you can validate an emails field using chips.
First, create the p-chips element and add the onAdd event to check every time the user validate a chip :
code :
<p-chips [(ngModel)]="emails" (onAdd)=testMail($event)></p-chips>
testMail(event) {
  this.errorMessage = ''; // reinitialize error message

  if(!this.validateEmail(event.value)) {
    this.errorMessage = event.value + ' is not a valid mail address !'; // display message
    this.emails.pop(); // remove last entry from emails array of strings
  }
}

How to validate email input field for multiple email separated by comma or semi-clone in Bootstrapvalidator


By : user3547166
Date : March 29 2020, 07:55 AM
will be helpful for those in need I've one text area for multiple email input and I want to validate emails with the bootstrap validator. I can't do this because there is an option for multiple which is by default false and I cannot make it true. , From the link you provided:
code :
$(document).ready(function() {
    $('#emailForm').bootstrapValidator({
                feedbackIcons: {
                    valid: 'glyphicon glyphicon-ok',
                    invalid: 'glyphicon glyphicon-remove',
                    validating: 'glyphicon glyphicon-refresh'
                },
                fields: {
                    email: {
                        validators: {
                            notEmpty: {
                                message: 'Email is required and cannot be empty'
                            },
                            emailAddress: {
                                message: 'The value is not a valid email address'
                            }
                        }
                    }
                }
            });
});
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-validator/0.5.3/js/bootstrapValidator.js"></script>
</head>
<body>


<form id="emailForm" class="form-horizontal">
    <div class="form-group">
<label for="email" class="col-sm-4 control-label"><span class="required">*</span> Email</label>
<div class="col-sm-8">
    <textarea id="company_email" name="email" class="form-control pull-left" rows="2" placeholder="Email" data-bv-emailaddress-multiple="true" data-bv-emailaddress="true"></textarea>
</div>
</form>


</body>
</html>

How to display error onblur when a field is empty using jQuery Validate?


By : IamListening
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , The plugin in question has a function specifically to run validation immediately on one particular element called 'element.' You can use this within the onfocusout function to force validation of that particular element.
Example:
Related Posts Related Posts :
  • Convert Javascript regex to Typescript regex
  • Textext.js - Remove all tags and clean textarea
  • Array splice with unexpected results
  • Having trouble with multiple active states in ReactJS
  • Error 500 for some Ajax requests on server
  • Event call at the end of HTTP call
  • wooommerce add to cart based on gravity form radio button
  • Angular 6: table with *ngIF generates one <td> more than i need
  • how to load an external script with react?
  • Getting current stored value from database in a form on Cascading dropdowns in edit mode C# MVC
  • Best Way to Pass Query Parameters to URL Using Axios in Vue?
  • Javascript - issues with regex expression
  • JqxCombo values not setting from ajax result - Vue.js
  • How to embed Google Custom Search in React App?
  • Compare objects recursively and put duplicate key values into array
  • How do I add TypeScript types to a JavaScript module without switching to TypeScript?
  • How to remove obsolete callback from set event listener?
  • JavaScript - Inflation/Escalation with Total over X years
  • Perform calculation in higher order component in reactJS
  • React doesn't update component after state changes
  • Javascript - Collect data from mongodb from multiple collections then merge into array
  • Session.cookies.get_dict() return an empty dictionary
  • Performing logical operation inside Higher Order Component on prop set
  • how to force the browser to run the javascript every time it called
  • REGEX get all content after a series of special characters
  • deduce amount issue, not the same value foreach execute
  • Regex to get individual function bodies from group of functions
  • Stop animation from executing if coming from an internal link
  • How to retrieve total of "else if"
  • Multiple JS slideshows on one page
  • Importing async functions in Javascript
  • How to handle state on array of checkboxes?
  • React Native - Redux ~ Props updating when not getting called
  • Fast way to add elements into an Uint8ClampedArray typed array
  • How to retrieve values from a checkbox group generated dinamically with jquery when page loads
  • Progress bar between two dates (fetch "var" from script), HTML
  • Why do Every time I start my function I get NaN
  • Angular routing change in url
  • Javascript - Change symbol on embedded tradingview script.text
  • How to select specific option?
  • Checking booleans from multiple arrays simultaneously, without multiple if statements
  • How to get a subarray?
  • Javascript JSON woes
  • Use Jquery animate to have a button move a box to the next corner
  • Why is this JavaScript not interpreted as a code block when semi-colon is used?
  • Reload another page when I click on button
  • Should functions that call a callback function be bound?
  • For loop print in single line separated by spaces - JS
  • Add Javascript Variable into asp-route-data
  • Two different POST requests are making use of the same variable
  • Convert JSOn object into a flat JSON Array
  • Manually adding to an HTML range input gives unexpected results
  • Refreshing component after making api call Reactjs
  • Google App Script : Finding The Last Blank Row
  • I cant for the life of me figure out whats wrong with this script
  • Order divs by ID in Javascript
  • set new element class property value
  • How to pass a java variable to a different jsp page containing javascript?
  • Locked it method in chai
  • React JS : history.push is not a function error and it isn't navigating to a different page onclick of swal
  • shadow
    Privacy Policy - Terms - Contact Us © voile276.org