If max number of student exceeded in the class

If max number of student exceeded in the class

Hay,

I have a Form named as add_class
1. school_name   (lookup field) from Form school_master 
2. program_name  (single line field)
3. max_student   (number field) 
4. start_date        (date field)
5. end_date         (date field)

And in my website there is Form named as Registration. Which have many different fields including
school_name, program_name, start_date and end_date .

what i need is when the max_student value exceeded for that particular program_name in that school_name then nobody can submit more entry in Registration Form in website , instead if anybody fill and submit Registration Form then it shows alert or popup to them that class is full can not add more.

And also if the start_date is zoho.currentDate  then no one able to fill the Registration Form , shows alert or popup again as same.

Note:- In one particular school_name there will be many program_name And for every program_name the value of max_student is different .

How can i achieve this ?  Thanks in advance for your help !!