Password

Password Field

Props:

Examples

import { whisper } from '@oliveai/ldk';
import { 
  NewWhisper, 
  UpdateWhisper, 
  Whisper, 
  WhisperComponentType 
} from "@oliveai/ldk/dist/whisper"

const validatePassword = (password: string) => {
  const regExpLetters = /[a-zA-Z]/g
  const regExpNumbers = /\d/

  if (password.length < 8) {

    return "Password Must be atleast 8 characters long!"
  } else if (!regExpLetters.test(password) ){

    return "Password must contain aleast 1 letter!"
  } else if (!regExpNumbers.test(password) ){

    return "Password must contain aleast 1 number!"
  } else {

    return ''
  }

}

const passwordExampleConfig = ( (value: string, validationError: string): NewWhisper | UpdateWhisper => {
  return {
    label: 'Password Example',
    components: [
      {
        type: WhisperComponentType.Password,
        label: 'Password',
        tooltip: 'Password Must be atleast 8 characters and include letters and numbers',
        validationError: validationError,
        value: value,
        onChange: (error: Error, password: string, whisper: Whisper) => {
          if (error) {
            console.debug(error)
          }
          whisper.update(passwordExampleConfig(password, validatePassword(password)))
        }

      }
    ]
  }
})

const newPasswordExampleConfig = (async () => {
  await whisper.create(passwordExampleConfig('', '') as NewWhisper);
})

newPasswordExampleConfig();

Last updated