How to show alert based on text input field validation

I have a requirement like this

user will input a number in text box and press enter
a backend web service will be called on action and it validate the input number
if number is invalid then an alert should pop up saying “invalid number”

I was able to validate the number writing a ws call inside action method but not sure how to show the popup alert from server side