Validate a Chess Move

This checks for valid algebraic notation. I mostly adhered to FIDE's rules, but to handle a few more common notations I expanded it a bit. Both 0-0-0 and 0-0 are validated with zeros or capital Os. Promotions are acceptable written as both d8Q and d8=Q. I also allow P to indicate a pawn, even though that's not technically correct (e.g. e4 is preferred over Pe4). Note that this is case sensitive and space sensitive (e.g. ke4+(=) is invalid but Ke4+ (=) is valid).

Validate Notation:

Is valid: false

"parsed": {
  "notation": "",
  "language": "english",
  "offeredDraw": null,
  "enPassant": null,
  "check": null,
  "checkmate": null,
  "queensideCastle": null,
  "kingsideCastle": null,
  "promotion": null,
  "to": null,
  "capture": null,
  "from": null,
  "piece": "Pawn",
  "notationAfterParsing": ""
}

If you need help finding a notation to validate, you can check out all the possible legal ones here. If you want to see the code used to validate the notation, you can see that here.

Some fun questions to answer:

  • Which moves can a king make that will never result in a check?
  • When is a draw offer (e.g. d4 (=)) not valid?
  • Where can a pawn never move from?

Did you find an error? Let me know below please!

Copyright Jonathan Walters © 2022