Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

react input number validation

// Validation with REGEX
const rx_live = /^[+-]?d*(?:[.,]d*)?$/;

class TestForm extends React.Component {
  constructor() {
    super();
    this.state = {
      depositedAmount: ''
    };
  }

  handleDepositeAmountChange = (evt) => {
    if (rx_live.test(evt.target.value))
        this.setState({ depositedAmount : evt.target.value });
 }
  
  render() {
    return (
      <form>
       <input
        type="text"
        id="depositedAmount"
        maxLength={9}
        pattern="[+-]?d+(?:[.,]d+)?"
        placeholder="Enter amount"
        onChange={this.handleDepositeAmountChange}
        value={this.state.depositedAmount}
       />
      </form>
    )
  }
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: how to get element by id 
Javascript :: remove char from string js 
Javascript :: jquery attr 
Javascript :: passing livewire variable in alpine js 
Javascript :: loop through array javascript 
Javascript :: js exit function 
Javascript :: js create json array 
Javascript :: calculate width of text javascript 
Javascript :: url regular expression 
Javascript :: difference between indexof and search in javascript 
Javascript :: how to run js before submit html 
Javascript :: font google expo 
Javascript :: handlerbar console log 
Javascript :: why is my deleteOne mongoose middleware not working 
Javascript :: How to make blinking/flashing text with jQuery 
Javascript :: convert string to camel case 
Javascript :: react app js 
Javascript :: unfocus javascript 
Javascript :: how to manage a db connection in javascript 
Javascript :: discord.js remove every role a user has 
Javascript :: how to remove last element in js 
Javascript :: how to compare two time in moment js 
Javascript :: react-native razorpay 
Javascript :: how to get the data from url in javascript 
Javascript :: export all functions 
Javascript :: javascript how to sort alphabetically 
Javascript :: firebase timestamp to date angular 
Javascript :: react scroll 
Javascript :: jquery form serialize object 
Javascript :: ionic react use yarn 
ADD CONTENT
Topic
Content
Source link
Name
7+7 =