خرید بک لینک

Vote count: 0

I am working on a project where I need to validate multiple dates based on length and pattes. I am using simple date format and found many issues with that. My requirement is to strictly allow if date string matches "yyyy/MM/dd" and strictly 10 characters.

The below code is not giving expected results for various testing input strings.

public static boolean checkformat(String dateString){
        boolean flag = false;
        Date d1 = null;
        SimpleDateFormat format = new SimpleDateFormat("yyyy/MM/dd");
        format.setLenient(false);
        try {
            d1 = format.parse(dateString);
            flag=true;
        } catch (ParseException ex) {
            ex.printStackTrace();
            retu false;
        }
        retu flag;
    }

the above code is retuing "true" for various inputs like "99/03/1" (should be 0099/03/01) and 99/1/1( should be 0099/01/1). Since the input strings are not coming from a from so I cant perform validations before passing them to this method. Please suggest any implementation which should act very strict towards the dateformat("yyyy/MM/dd").

asked 1 min ago

- - , .

برچسب: نویسنده: استخدام کار تاريخ: شنبه 24 بهمن 1394 ساعت: 12:35

صفحه بندی