Regular expressions for checking input in chess?

I am working on a hobby chess project with HTML / CSS / PHP. I was not familiar with chess before, so I decided to create an instrument that would show which moves were allowed based on the type and square of the given part.

I have an HTML form with two text fields: one for the fragment type, and the other for the current square of the specified part. Everything works, but I want to enable validation using regular expressions.

Valid, case-insensitive input for the part type: p, pawn, r, rook, b, bishop, n, knight, q, queen, k, king.

Valid, case-insensitive inputs for a square are LetterNumber, where Letter can be AH and the number can be 1-8.

So, I am wondering if regular expressions / practicals are possible, and if so, can someone tell me what it is? I think I should just use a conditional statement with logical elements for the type of pieces, but I'm curious to see if there are other solutions.

+5
source share
3 answers

Regular expressions on inputs:

  • Piece: ^ [p | r | b | n | q | k | P | R | B | N | Q | K] $
  • Position: ^ [AH | ah] [1-8] $

You can evaluate onblur, onchange and onsubmit for the form.

I agree that checking the move on the client side and on the server side will also be of great importance.

+4
source

Chess movement validation programming

, , , , ( , ), , ( , , , ).

, :

1 algoritm . ( ). ( , ;]) ( , .)

:  - , .  - ,  - " " - . . Castling " " " ", , - ( , , . . .)


PHP

php, , , :

http://www.bebogame.com/download/php/multiplayer_chess/multiplayer_chess.zip

http://sourceforge.net/projects/some-chess/files/Some%20Chess%202.0/Some%20Chess%202.0%20beta%203/SomeChess_2.0b3.tbz/download

http://www.redlionwebdesign.com/phpchess.htm

+8

I highly recommend against regex for such a task. The actual movements of any given part refer to its current position and color and are better checked with the check function.

+2
source

All Articles