Palindrome Tester

by Christian Juth

HTML

<h2>Enter a palindrome and submit to test it<h2>
<form id="palindrome">
    <input class="phrase" type="text" required>
    <input type="submit" value="submit">
</form>

JavaScript

$('#palindrome').submit(function (e) {
    e.preventDefault();
    var phrase = $(this).find('.phrase').val().toLowerCase();
    alert(palindrome(phrase));
});

palindrome = function (txt) {
    txt = txt.replace(/(\s|,|\.)/ig, '');
    return txt == txt.split('').reverse().join('');
}