How can I check if the user has input a null or empty string in classic-asp? Right now I am have this code.
If Request.Form("productId") == "" Then
'my code here
End If
But its not working.
The IsNullOrEmpty() method returns true if the input is null . IsNullOrEmpty() returns true if the input is an empty string.
You can use the IsNullOrWhiteSpace method to test whether a string is null , its value is String. Empty, or it consists only of white-space characters.
Use blank=True if you'd like to make input optional so that the user doesn't need to enter anything.
To prevent an empty user input: Use a while loop to iterate until the user enters a non-empty string. On each iteration, check if the user didn't enter an empty string. If the condition is met, break out of the while loop.
Classic ASP/VBScript uses one = to check for equality, not two. Another thing you may want to try is
If Request.Form("productid") = "" Then
Code here
End If
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With