JSFiddle - React, Tailwind, and code Playground
HTML
<input id="calc" type="text"/>
<br />
<div id='result' />
JavaScript
/*global $ */
(function() {
'use strict';
$('#calc').on('blur', function(e) {
var val = $('#calc').val(),
result;
if (/[^\d\s+\-*\/]+/g.test(val)) {
result = 'undefined';
} else {
result = eval(val);
}
$('#calc').val(result);
});
}());