简体   繁体   中英

Is it possible to validate a minimum signature was drawn on angular2-signaturepad?

I am using angular2-signaturepad to collect digital signatures in an angular 6 application. Some users are just drawing a simple dot or straight line. Is it possible to require users to enter more than a few dots or a line? I'm not trying to verify a name or full signature, just that they drew more than a tiny signature. Thank you in advance.

My suggestion would be take canvas and check pixels

 var p = c.getImageData(x, y, 1, 1).data; 
 var hex = "#" + ("000000" + rgbToHex(p[0], p[1], p[2])).slice(-6);

So you should check how many are not empty.

Source

You can also validate for a minimum number of xy points in signaturePad.toData() . Here's an example validation method that looks for a minimum number of points.

hasComplexity(pad: SignaturePad, complexity?: number) {
  if (!complexity) {
    complexity = 10;
  }
  const points = pad.toData();
  const pointCount = [].concat.apply([], points).length;
  return points && pointCount >= complexity;
}

Usage example:

const isValid = this.hasComplexity(this.pad, 10);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM