You can use below JavaScript function to execute any JavaScript Code in New or Edit Forms for SharePoint List before saving (When Pressing OK button this function will be fired first)
You can use this function for validation before PostBack
PreSaveAction()
{
//Add Your JavaScript Code Here Then Return True Or False
return false; // Cancel the item save process
return true; // OK to proceed with the save item
}