What’s an appropriate HTTP status code to return by a REST API service for a validation failure?

If “validation failure” means that there is some client error in the request, then use HTTP 400 (Bad Request). For instance if the URI is supposed to have an ISO-8601 date and you find that it’s in the wrong format or refers to February 31st, then you would return an HTTP 400. Ditto if you … Read more

Check if inputs are empty using jQuery

$(‘#apply-form input’).blur(function() { if( !$(this).val() ) { $(this).parents(‘p’).addClass(‘warning’); } }); And you don’t necessarily need .length or see if it’s >0 since an empty string evaluates to false anyway but if you’d like to for readability purposes: $(‘#apply-form input’).blur(function() { if( $(this).val().length === 0 ) { $(this).parents(‘p’).addClass(‘warning’); } }); If you’re sure it will always … Read more

Which characters make a URL invalid?

In general URIs as defined by RFC 3986 (see Section 2: Characters) may contain any of the following 84 characters: ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~:/?#[]@!$&'()*+,;= Note that this list doesn’t state where in the URI these characters may occur. Any other character needs to be encoded with the percent-encoding (%hh). Each part of the URI has further restrictions about … Read more

How to allow only numeric (0-9) in HTML inputbox using jQuery?

Note: This is an updated answer. Comments below refer to an old version which messed around with keycodes. jQuery Try it yourself on JSFiddle. There is no native jQuery implementation for this, but you can filter the input values of a text <input> with the following inputFilter plugin (supports Copy+Paste, Drag+Drop, keyboard shortcuts, context menu … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)