Adding up particular part of String from a Value input

I'm now working on a piece of code where I need to add the first 3 characters on the string, and then compare them to the last 2 characters to make sure they match.

e.g: ID 12306 is Valid, as 1+2+3 = 6, and 0+6 = 6.

I did find a topic previously on here (back in 2012) regarding a similar issue, however the code example used 2 static number variables, and when I tried to implement the same method using my HTML input value, it seems to do nothing.