I have a form that I want to validate on one of the input and i use react hook form . This is the validation I want to apply:
const validateSheba=(str)=> {
var pattern = /IR[0-9]{24}/;
if (str.length !== 26) {
return false;
}
if (!pattern.test(str)) {
return false;
}
var newStr = str.substr(4);
var d1 = str.charCodeAt(0) - 65 + 10;
var d2 = str.charCodeAt(1) - 65 + 10;
newStr += d1.toString() + d2.toString() + str.substr(2, 2);
var remainder = this.iso7064Mod97_10(newStr);
if (remainder !== 1) {
return false;
}
return true;
};
And that's how I used it:
<Input
name="Sheba"
placeholder="Sheba"
ref={register({
required: true,
pattern: {
value:value=> validateSheba(value),
message: "not valid",
},
})}
error={errors?.Sheba ? true : false}
helperText={errors?.Sheba?.message}
inputClassName={classes.input}
></Input>
It does not work .. How should I do this?
register({ ... })to...register({ ... })?